-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ipc: use O_EXCL on SHM files #339
ipc: use O_EXCL on SHM files #339
Conversation
Signed-off-by: Christine Caulfield <[email protected]>
lib/ipc_setup.c
Outdated
@@ -657,9 +659,17 @@ handle_new_connection(struct qb_ipcs_service *s, | |||
qb_util_log(LOG_DEBUG, "IPC credentials authenticated (%s)", | |||
c->description); | |||
|
|||
retry_description: | |||
snprintf(c->description, CONNECTION_DESCRIPTION, | |||
"%d-%d-%lu", s->pid, ugp->pid, (unsigned long)(random()%65536)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately 16 bits of randomness is way too little, it's easy to create 64k files quickly. I'd use 64 bits as minimum. Does the protocol require a decimal number here, could it be hex or Base64 formatted instead? I'm not sure random() is a good generator of secure random numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point
lib/ipcs.c
Outdated
if (fd == -1) { | ||
seed = (time_t)time(NULL); | ||
} else { | ||
if (read(fd, &seed, sizeof(seed)) != 4) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This effectively gives 32 bits of randomness to the generator. Theoretically it's not impossible to break by brute forcing this kind of number space, though in practice it might be impossible for the attacker to generate 2^32 files in /dev/shm. I'd still try to find out a way to get at least 64 bits of randomness to the file names to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
srand() only takes an int! Should I not be using random - even with a seed from /dev/urandom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a good implementation in systemd src/basic/random-util.c, though it may need some porting to run on non-Linux. It's also a bit complex.
Thanks. It does look a bit over the top. My idea for an alternative was to read 64 bits from /dev/urandom for each connection. If that fails (which is shouldn't of course) then fall back to 2 calls to random() |
Hm, and what about using POSIX 2008 endorsed Cons are an extra system resource to consume (inode per the directory I.e., turn
into something like
where the trailing XXXXXX corresponds to the semantics of Moreover, |
lib/log_blackbox.c
Outdated
@@ -188,7 +188,7 @@ qb_log_blackbox_write_to_file(const char *filename) | |||
ssize_t written_size = 0; | |||
struct qb_log_target *t; | |||
struct _blackbox_file_header header; | |||
int fd = open(filename, O_CREAT | O_RDWR, 0700); | |||
int fd = open(filename, O_CREAT | O_RDWR | O_EXCL, 0700); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O_RDWR
shall likely be flipped to O_WRONLY
.
O_EXCL
is dubious, overwriting existing file is a valid use case
here and an established semantics of the function.
Perhaps devising qb_log_blackbox_write_to_file_2
with some expressly
noted flags passable as flags
and making qb_log_blackbox_write_to_file
depend on that might be a better idea.
I'm sympathetic to the idea of mkdtemp, but annoyingly it's not compatible with shm_open() as far as I can tell. FreeBSD's shm_open() call has no filesystem visibility at all. Although it does allow a '/' in filename I'm not sure if they count as a directory as such - or even what that would mean. As we need this security patch for the 1.0.x stream are people happy with my patch as posted and modified for this branch, then we'll look at something a bit more sophisticated for the 2.0 branch? |
Since Also, Last but not least (quite the contrary!), with your current approach, With properly guarded intermediate directory, this wouldn't happen, |
There's WIP using Regarding the tracing tool, it'd be indeed helpful for remote debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks sane to me
Sane with respect to the primary goal, yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just an explicit expression to accompany my previous comment)
Use O_EXCL on IPC files
I'm going to shrink this patch so it only has the O_EXCL bits in. The other part can be looked at separately as it's just going to get too messy. |
patch has changed since original submission and reduced in scope
Signed-off-by: Christine Caulfield [email protected]