Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F166780014
D8543.id22267.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D8543.id22267.diff
View Options
Index: freebsd/bin/dd/dd.c
===================================================================
--- freebsd/bin/dd/dd.c
+++ freebsd/bin/dd/dd.c
@@ -48,11 +48,14 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/conf.h>
+#include <sys/capsicum.h>
#include <sys/disklabel.h>
#include <sys/filio.h>
+#include <sys/mtio.h>
#include <sys/time.h>
#include <assert.h>
+#include <capsicum_helpers.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -90,6 +93,13 @@
(void)setlocale(LC_CTYPE, "");
jcl(argv);
setup();
+ caph_cache_tzdata();
+ caph_cache_catpages();
+ if (cap_enter() == -1) {
+ if (errno != ENOSYS)
+ err(1, "cap_enter() failed");
+ warn("Capsicum unavailable, running without a sandbox");
+ }
(void)signal(SIGINFO, siginfo_handler);
(void)signal(SIGINT, terminate);
@@ -125,6 +135,8 @@
{
u_int cnt;
struct timeval tv;
+ cap_rights_t rights;
+ unsigned long cmds[] = {MTIOCTOP, FIODTYPE};
if (in.name == NULL) {
in.name = "stdin";
@@ -133,13 +145,20 @@
in.fd = open(in.name, O_RDONLY, 0);
if (in.fd == -1)
err(1, "%s", in.name);
+ if (caph_limit_stdin() == -1)
+ err(1, "Unable to limit capability rights");
}
getfdtype(&in);
+ cap_rights_init(&rights, CAP_READ, CAP_SEEK);
+ if (cap_rights_limit(in.fd, &rights) == -1 && errno != ENOSYS)
+ err(1, "Unable to limit capability rights");
+
if (files_cnt > 1 && !(in.flags & ISTAPE))
errx(1, "files is not supported for non-tape devices");
+ cap_rights_set(&rights, CAP_WRITE, CAP_FTRUNCATE, CAP_IOCTL);
if (out.name == NULL) {
/* No way to check for read access here. */
out.fd = STDOUT_FILENO;
@@ -148,6 +167,7 @@
#define OFLAGS \
(O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC))
out.fd = open(out.name, O_RDWR | OFLAGS, DEFFILEMODE);
+
/*
* May not have read access, so try again with write only.
* Without read we may have a problem if output also does
@@ -156,13 +176,27 @@
if (out.fd == -1) {
out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
out.flags |= NOREAD;
+ cap_rights_clear(&rights, CAP_READ);
}
if (out.fd == -1)
err(1, "%s", out.name);
+ if (caph_limit_stdout() == -1 && errno != ENOSYS)
+ err(1, "Unable to limit capability rights");
}
getfdtype(&out);
+ if (cap_rights_limit(out.fd, &rights) == -1 && errno != ENOSYS)
+ err(1, "Unable to limit capability rights");
+ if (cap_ioctls_limit(out.fd, cmds, nitems(cmds)) == -1 &&
+ errno != ENOSYS)
+ err(1, "Unable to limit capability rights");
+
+ if (in.fd != STDERR_FILENO && out.fd != STDERR_FILENO) {
+ if (caph_limit_stderr() == -1 && errno != ENOSYS)
+ err(1, "Unable to limit capability rights");
+ }
+
/*
* Allocate space for the input and output buffers. If not doing
* record oriented I/O, only need a single buffer.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 17, 1:19 PM (3 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36856762
Default Alt Text
D8543.id22267.diff (2 KB)
Attached To
Mode
D8543: Capsicumise dd
Attached
Detach File
Event Timeline
Log In to Comment