Commit 20eee594 authored by Zhong Jinghua's avatar Zhong Jinghua Committed by Li Nan
Browse files

nbd: Reorganize the messy commit log about the first_minor check



hulk inclusion
category: bugfix
bugzilla: 188217

----------------------------------------

Commits on our branch with check issues on first_minor had serious
confusion, resulting in duplicate checks in nbd_dev_add and
nbd_genl_connect.

So I revert the messy commit, backport lts patch.

Revert 84c282c6
  ("nbd: fix possible overflow for 'first_minor' in nbd_dev_add()")
Revert 39a42d5e ("nbd: fix max value for 'first_minor'")
Revert 3ddba49a
  ("Revert "Revert "block: nbd: add sanity check for first_minor""")
Revert 3bb2913d
  ("nbd: fix assignment error for first_minor in nbd_dev_add")
Revert 648bb72a
  ("nbd: fix possible overflow on 'first_minor' in nbd_dev_add()")
Revert 60141517 ("nbd: Fix use-after-free in blk_mq_free_rqs")
Revert 98d3ad1d ("nbd: add sanity check for first_minor")

Signed-off-by: default avatarZhong Jinghua <zhongjinghua@huawei.com>
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
parent bcf0a9c4
Loading
Loading
Loading
Loading
+1 −23
Original line number Diff line number Diff line
@@ -1875,17 +1875,7 @@ static int nbd_dev_add(int index)
	refcount_set(&nbd->refs, 1);
	INIT_LIST_HEAD(&nbd->list);
	disk->major = NBD_MAJOR;

	/* Too big first_minor can cause duplicate creation of
	 * sysfs files/links, since index << part_shift might overflow, or
	 * MKDEV() expect that the max bits of first_minor is 20.
	 */
	disk->first_minor = index << part_shift;
	if (disk->first_minor < index || disk->first_minor > MINORMASK) {
		err = -EINVAL;
		goto out_free_idr;
	}

	disk->fops = &nbd_fops;
	disk->private_data = nbd;
	sprintf(disk->disk_name, "nbd%d", index);
@@ -1972,20 +1962,8 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
	if (!netlink_capable(skb, CAP_SYS_ADMIN))
		return -EPERM;

	if (info->attrs[NBD_ATTR_INDEX]) {
	if (info->attrs[NBD_ATTR_INDEX])
		index = nla_get_u32(info->attrs[NBD_ATTR_INDEX]);

		/*
		 * Too big first_minor can cause duplicate creation of
		 * sysfs files/links, since index << part_shift might
		 * overflow, or MKDEV() expect that the max bits of
		 * first_minor is 20.
		 */
		if (index < 0 || index > MINORMASK >> part_shift) {
			printk(KERN_ERR "nbd: illegal input index %d\n", index);
			return -EINVAL;
		}
	}
	if (!info->attrs[NBD_ATTR_SOCKETS]) {
		printk(KERN_ERR "nbd: must specify at least one socket\n");
		return -EINVAL;