.. | .. |
---|
1624 | 1624 | return -EIO; |
---|
1625 | 1625 | |
---|
1626 | 1626 | dir = debugfs_create_dir(nbd_name(nbd), nbd_dbg_dir); |
---|
1627 | | - if (!dir) { |
---|
| 1627 | + if (IS_ERR(dir)) { |
---|
1628 | 1628 | dev_err(nbd_to_dev(nbd), "Failed to create debugfs dir for '%s'\n", |
---|
1629 | 1629 | nbd_name(nbd)); |
---|
1630 | 1630 | return -EIO; |
---|
.. | .. |
---|
1650 | 1650 | struct dentry *dbg_dir; |
---|
1651 | 1651 | |
---|
1652 | 1652 | dbg_dir = debugfs_create_dir("nbd", NULL); |
---|
1653 | | - if (!dbg_dir) |
---|
| 1653 | + if (IS_ERR(dbg_dir)) |
---|
1654 | 1654 | return -EIO; |
---|
1655 | 1655 | |
---|
1656 | 1656 | nbd_dbg_dir = dbg_dir; |
---|
.. | .. |
---|
1723 | 1723 | if (err == -ENOSPC) |
---|
1724 | 1724 | err = -EEXIST; |
---|
1725 | 1725 | } else { |
---|
1726 | | - err = idr_alloc(&nbd_index_idr, nbd, 0, 0, GFP_KERNEL); |
---|
| 1726 | + err = idr_alloc(&nbd_index_idr, nbd, 0, |
---|
| 1727 | + (MINORMASK >> part_shift) + 1, GFP_KERNEL); |
---|
1727 | 1728 | if (err >= 0) |
---|
1728 | 1729 | index = err; |
---|
1729 | 1730 | } |
---|
.. | .. |
---|
1865 | 1866 | if (!netlink_capable(skb, CAP_SYS_ADMIN)) |
---|
1866 | 1867 | return -EPERM; |
---|
1867 | 1868 | |
---|
1868 | | - if (info->attrs[NBD_ATTR_INDEX]) |
---|
| 1869 | + if (info->attrs[NBD_ATTR_INDEX]) { |
---|
1869 | 1870 | index = nla_get_u32(info->attrs[NBD_ATTR_INDEX]); |
---|
| 1871 | + |
---|
| 1872 | + /* |
---|
| 1873 | + * Too big first_minor can cause duplicate creation of |
---|
| 1874 | + * sysfs files/links, since index << part_shift might overflow, or |
---|
| 1875 | + * MKDEV() expect that the max bits of first_minor is 20. |
---|
| 1876 | + */ |
---|
| 1877 | + if (index < 0 || index > MINORMASK >> part_shift) { |
---|
| 1878 | + printk(KERN_ERR "nbd: illegal input index %d\n", index); |
---|
| 1879 | + return -EINVAL; |
---|
| 1880 | + } |
---|
| 1881 | + } |
---|
1870 | 1882 | if (!info->attrs[NBD_ATTR_SOCKETS]) { |
---|
1871 | 1883 | printk(KERN_ERR "nbd: must specify at least one socket\n"); |
---|
1872 | 1884 | return -EINVAL; |
---|