mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 03:35:32 -04:00
binfmt_misc: annotate racy accesses to ->enabled
->enabled has always been read and written locklessly: every exec reads it in load_misc_binary() while bm_status_write() or a concurrent remount via bm_fill_super() may flip it. That is fine as it is an independent boolean toggle but the accesses should be marked accordingly for KCSAN. Annotate them with READ_ONCE()/WRITE_ONCE(). Link: https://patch.msgid.link/20260710-work-binfmt_misc-locking-v3-6-a162f7cb58d6@kernel.org Reviewed-by: Jori Koolstra <jkoolstra@xs4all.nl> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
@@ -217,7 +217,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
|
||||
struct binfmt_misc *misc;
|
||||
|
||||
misc = load_binfmt_misc();
|
||||
if (!misc->enabled)
|
||||
if (!READ_ONCE(misc->enabled))
|
||||
return retval;
|
||||
|
||||
fmt = get_binfmt_handler(misc, bprm);
|
||||
@@ -874,7 +874,7 @@ bm_status_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
||||
char *s;
|
||||
|
||||
misc = i_binfmt_misc(file_inode(file));
|
||||
s = misc->enabled ? "enabled\n" : "disabled\n";
|
||||
s = READ_ONCE(misc->enabled) ? "enabled\n" : "disabled\n";
|
||||
return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s));
|
||||
}
|
||||
|
||||
@@ -891,11 +891,11 @@ static ssize_t bm_status_write(struct file *file, const char __user *buffer,
|
||||
switch (res) {
|
||||
case 1:
|
||||
/* Disable all handlers. */
|
||||
misc->enabled = false;
|
||||
WRITE_ONCE(misc->enabled, false);
|
||||
break;
|
||||
case 2:
|
||||
/* Enable all handlers. */
|
||||
misc->enabled = true;
|
||||
WRITE_ONCE(misc->enabled, true);
|
||||
break;
|
||||
case 3:
|
||||
/* Delete all handlers. */
|
||||
@@ -1000,7 +1000,7 @@ static int bm_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
* is true. Instead, if someone mounts binfmt_misc for the first time or
|
||||
* again we simply reset ->enabled to true.
|
||||
*/
|
||||
misc->enabled = true;
|
||||
WRITE_ONCE(misc->enabled, true);
|
||||
|
||||
err = simple_fill_super(sb, BINFMTFS_MAGIC, bm_files);
|
||||
if (!err)
|
||||
|
||||
Reference in New Issue
Block a user