Skip to content

Commit

Permalink
drivers: avoid format string in dev_set_name
Browse files Browse the repository at this point in the history
Calling dev_set_name with a single paramter causes it to be handled as a
format string.  Many callers are passing potentially dynamic string
content, so use "%s" in those cases to avoid any potential accidents,
including wrappers like device_create*() and bdi_register().

Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kees authored and torvalds committed Jul 3, 2013
1 parent 096a8aa commit 02aa2a3
Show file tree
Hide file tree
Showing 23 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion drivers/base/attribute_container.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
ic->classdev.parent = get_device(dev);
ic->classdev.class = cont->class;
cont->class->dev_release = attribute_container_release;
dev_set_name(&ic->classdev, dev_name(dev));
dev_set_name(&ic->classdev, "%s", dev_name(dev));
if (fn)
fn(cont, dev, &ic->classdev);
else
Expand Down
2 changes: 1 addition & 1 deletion drivers/devfreq/devfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
GFP_KERNEL);
devfreq->last_stat_updated = jiffies;

dev_set_name(&devfreq->dev, dev_name(dev));
dev_set_name(&devfreq->dev, "%s", dev_name(dev));
err = device_register(&devfreq->dev);
if (err) {
put_device(&devfreq->dev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/extcon/extcon-class.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
edev->dev->class = extcon_class;
edev->dev->release = extcon_dev_release;

dev_set_name(edev->dev, edev->name ? edev->name : dev_name(dev));
dev_set_name(edev->dev, "%s", edev->name ? edev->name : dev_name(dev));

if (edev->max_supported) {
char buf[10];
Expand Down
2 changes: 1 addition & 1 deletion drivers/hsi/hsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void hsi_new_client(struct hsi_port *port, struct hsi_board_info *info)
cl->device.bus = &hsi_bus_type;
cl->device.parent = &port->device;
cl->device.release = hsi_client_release;
dev_set_name(&cl->device, info->name);
dev_set_name(&cl->device, "%s", info->name);
cl->device.platform_data = info->platform_data;
if (info->archdata)
cl->device.archdata = *info->archdata;
Expand Down
2 changes: 1 addition & 1 deletion drivers/ide/ide-cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ static int ide_cd_probe(ide_drive_t *drive)

info->dev.parent = &drive->gendev;
info->dev.release = ide_cd_release;
dev_set_name(&info->dev, dev_name(&drive->gendev));
dev_set_name(&info->dev, "%s", dev_name(&drive->gendev));

if (device_register(&info->dev))
goto out_free_disk;
Expand Down
2 changes: 1 addition & 1 deletion drivers/ide/ide-gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int ide_gd_probe(ide_drive_t *drive)

idkp->dev.parent = &drive->gendev;
idkp->dev.release = ide_disk_release;
dev_set_name(&idkp->dev, dev_name(&drive->gendev));
dev_set_name(&idkp->dev, "%s", dev_name(&drive->gendev));

if (device_register(&idkp->dev))
goto out_free_disk;
Expand Down
4 changes: 2 additions & 2 deletions drivers/ide/ide-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static int ide_register_port(ide_hwif_t *hwif)
int ret;

/* register with global device tree */
dev_set_name(&hwif->gendev, hwif->name);
dev_set_name(&hwif->gendev, "%s", hwif->name);
dev_set_drvdata(&hwif->gendev, hwif);
if (hwif->gendev.parent == NULL)
hwif->gendev.parent = hwif->dev;
Expand All @@ -559,7 +559,7 @@ static int ide_register_port(ide_hwif_t *hwif)
}

hwif->portdev = device_create(ide_port_class, &hwif->gendev,
MKDEV(0, 0), hwif, hwif->name);
MKDEV(0, 0), hwif, "%s", hwif->name);
if (IS_ERR(hwif->portdev)) {
ret = PTR_ERR(hwif->portdev);
device_unregister(&hwif->gendev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/ide/ide-tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ static int ide_tape_probe(ide_drive_t *drive)

tape->dev.parent = &drive->gendev;
tape->dev.release = ide_tape_release;
dev_set_name(&tape->dev, dev_name(&drive->gendev));
dev_set_name(&tape->dev, "%s", dev_name(&drive->gendev));

if (device_register(&tape->dev))
goto out_free_disk;
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ int ib_device_register_sysfs(struct ib_device *device,

class_dev->class = &ib_class;
class_dev->parent = device->dma_device;
dev_set_name(class_dev, device->name);
dev_set_name(class_dev, "%s", device->name);
dev_set_drvdata(class_dev, device);

INIT_LIST_HEAD(&device->port_list);
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/hw/qib/qib_file_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ int qib_cdev_init(int minor, const char *name,
goto err_cdev;
}

device = device_create(qib_class, NULL, dev, NULL, name);
device = device_create(qib_class, NULL, dev, NULL, "%s", name);
if (!IS_ERR(device))
goto done;
ret = PTR_ERR(device);
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/mISDN/dsp_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int mISDN_dsp_element_register(struct mISDN_dsp_element *elem)
entry->dev.class = elements_class;
entry->dev.release = mISDN_dsp_dev_release;
dev_set_drvdata(&entry->dev, elem);
dev_set_name(&entry->dev, elem->name);
dev_set_name(&entry->dev, "%s", elem->name);
ret = device_register(&entry->dev);
if (ret) {
printk(KERN_ERR "%s: failed to register %s\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name)

ret = bdi_init(bdi);
if (!ret)
ret = bdi_register(bdi, NULL, name);
ret = bdi_register(bdi, NULL, "%s", name);

if (ret)
bdi_destroy(bdi);
Expand Down
2 changes: 1 addition & 1 deletion drivers/platform/x86/wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ static int wmi_create_device(const struct guid_block *gblock,
wblock->dev.class = &wmi_class;

wmi_gtoa(gblock->guid, guid_string);
dev_set_name(&wblock->dev, guid_string);
dev_set_name(&wblock->dev, "%s", guid_string);

dev_set_drvdata(&wblock->dev, wblock);

Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,7 @@ static int sd_probe(struct device *dev)
device_initialize(&sdkp->dev);
sdkp->dev.parent = dev;
sdkp->dev.class = &sd_disk_class;
dev_set_name(&sdkp->dev, dev_name(dev));
dev_set_name(&sdkp->dev, "%s", dev_name(dev));

if (device_add(&sdkp->dev))
goto out_free_index;
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/android/timed_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)

tdev->index = atomic_inc_return(&device_count);
tdev->dev = device_create(timed_output_class, NULL,
MKDEV(0, tdev->index), NULL, tdev->name);
MKDEV(0, tdev->index), NULL, "%s", tdev->name);
if (IS_ERR(tdev->dev))
return PTR_ERR(tdev->dev);

Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/dgrp/dgrp_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void dgrp_create_node_class_sysfs_files(struct nd_struct *nd)
sprintf(name, "node%ld", nd->nd_major);

nd->nd_class_dev = device_create(dgrp_class, dgrp_class_nodes_dev,
MKDEV(0, nd->nd_major), NULL, name);
MKDEV(0, nd->nd_major), NULL, "%s", name);

ret = sysfs_create_group(&nd->nd_class_dev->kobj,
&dgrp_node_attribute_group);
Expand Down
2 changes: 1 addition & 1 deletion drivers/uwb/lc-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void uwbd_dev_onair(struct uwb_rc *rc, struct uwb_beca_e *bce)
uwb_dev_init(uwb_dev); /* This sets refcnt to one, we own it */
uwb_dev->mac_addr = *bce->mac_addr;
uwb_dev->dev_addr = bce->dev_addr;
dev_set_name(&uwb_dev->dev, macbuf);
dev_set_name(&uwb_dev->dev, "%s", macbuf);
result = uwb_dev_add(uwb_dev, &rc->uwb_dev.dev, rc);
if (result < 0) {
dev_err(dev, "new device %s: cannot instantiate device\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ struct backlight_device *backlight_device_register(const char *name,
new_bd->dev.class = backlight_class;
new_bd->dev.parent = parent;
new_bd->dev.release = bl_device_release;
dev_set_name(&new_bd->dev, name);
dev_set_name(&new_bd->dev, "%s", name);
dev_set_drvdata(&new_bd->dev, devdata);

/* Set default properties */
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/backlight/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
new_ld->dev.class = lcd_class;
new_ld->dev.parent = parent;
new_ld->dev.release = lcd_device_release;
dev_set_name(&new_ld->dev, name);
dev_set_name(&new_ld->dev, "%s", name);
dev_set_drvdata(&new_ld->dev, devdata);

rc = device_register(&new_ld->dev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
new_dev->props = op;
new_dev->dev.class = &video_output_class;
new_dev->dev.parent = dev;
dev_set_name(&new_dev->dev, name);
dev_set_name(&new_dev->dev, "%s", name);
dev_set_drvdata(&new_dev->dev, devdata);
ret_code = device_register(&new_dev->dev);
if (ret_code) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/xen/xenbus/xenbus_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ int xenbus_probe_node(struct xen_bus_type *bus,
if (err)
goto fail;

dev_set_name(&xendev->dev, devname);
dev_set_name(&xendev->dev, "%s", devname);

/* Register with generic device framework. */
err = device_register(&xendev->dev);
Expand Down
5 changes: 2 additions & 3 deletions mm/backing-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
unsigned int cap)
{
char tmp[32];
int err;

bdi->name = name;
Expand All @@ -524,8 +523,8 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
if (err)
return err;

sprintf(tmp, "%.28s%s", name, "-%d");
err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
err = bdi_register(bdi, NULL, "%.28s-%ld", name,
atomic_long_inc_return(&bdi_seq));
if (err) {
bdi_destroy(bdi);
return err;
Expand Down
2 changes: 1 addition & 1 deletion sound/sound_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
}

device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
NULL, s->name+6);
NULL, "%s", s->name+6);
return s->unit_minor;

fail:
Expand Down

0 comments on commit 02aa2a3

Please sign in to comment.