Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

configfs: fix kernel infoleak through user-controlled format string

Some modules call config_item_init_type_name() and config_group_init_type_name()
with parameter "name" directly controlled by userspace. These two
functions call config_item_set_name() with this name used as a format
string, which can be used to leak information such as content of the
stack to userspace.

For example, make_netconsole_target() in netconsole module calls
config_item_init_type_name() with the name of a newly-created directory.
This means that the following commands give some unexpected output, with
configfs mounted in /sys/kernel/config/ and on a system with a
configured eth0 ethernet interface:

# modprobe netconsole
# mkdir /sys/kernel/config/netconsole/target_%lx
# echo eth0 > /sys/kernel/config/netconsole/target_%lx/dev_name
# echo 1 > /sys/kernel/config/netconsole/target_%lx/enabled
# echo eth0 > /sys/kernel/config/netconsole/target_%lx/dev_name
# dmesg |tail -n1
[ 142.697668] netconsole: target (target_ffffffffc0ae8080) is
enabled, disable to update parameters

The directory name is correct but %lx has been interpreted in the
internal item name, displayed here in the error message used by
store_dev_name() in drivers/net/netconsole.c.

To fix this, update every caller of config_item_set_name to use "%s"
when operating on untrusted input.

This issue was found using -Wformat-security gcc flag, once a __printf
attribute has been added to config_item_set_name().

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Felipe Balbi <balbi@ti.com>
Acked-by: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Nicolas Iooss and committed by
Linus Torvalds
3958b792 8db14860

+3 -3
+1 -1
drivers/usb/gadget/configfs.c
··· 571 571 if (IS_ERR(fi)) 572 572 return ERR_CAST(fi); 573 573 574 - ret = config_item_set_name(&fi->group.cg_item, name); 574 + ret = config_item_set_name(&fi->group.cg_item, "%s", name); 575 575 if (ret) { 576 576 usb_put_function_instance(fi); 577 577 return ERR_PTR(ret);
+2 -2
fs/configfs/item.c
··· 115 115 const char *name, 116 116 struct config_item_type *type) 117 117 { 118 - config_item_set_name(item, name); 118 + config_item_set_name(item, "%s", name); 119 119 item->ci_type = type; 120 120 config_item_init(item); 121 121 } ··· 124 124 void config_group_init_type_name(struct config_group *group, const char *name, 125 125 struct config_item_type *type) 126 126 { 127 - config_item_set_name(&group->cg_item, name); 127 + config_item_set_name(&group->cg_item, "%s", name); 128 128 group->cg_item.ci_type = type; 129 129 config_group_init(group); 130 130 }