Skip to contentSkip to conversation

nbd_genl_status: null check for nla_nest_start

PATCH Superseded Navid Emamdoost 6 participants 11 messages Jul 23, 2019 – Apr 14, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nbd_genl_status: null check for nla_nest_start

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.

---
 drivers/block/nbd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/nbd.c +6 -0
index 9bcde2325893..dba362de4d91 100644
@@ -2149,6 +2149,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+
+	if (!dev_list) {
+		ret = -EMSGSIZE;
+		goto out;
+	}
+
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Navid Emamdoost

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.

---
 drivers/block/nbd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/nbd.c +0 -0
index 9bcde2325893..dba362de4d91 100644

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2152

Quoted 4 lines
drivers/block/nbd.c +1 -0
@@ -2149,6 +2149,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+

No newline here, once you fix that nit you can add

Thanks,

Josef

#2 lore raw

PATCH v2 1/1 nbd_genl_status: null check for nla_nest_start

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.

---
 drivers/block/nbd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/block/nbd.c +5 -0
index 9bcde2325893..2410812d1e82 100644
@@ -2149,6 +2149,11 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+	if (!dev_list) {
+		ret = -EMSGSIZE;
+		goto out;
+	}
+
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {
Signature · 1 line
2.17.1
#3 lore raw

Hi Navid,

Thank you for you report. I have forwarded this to our analysis team. Once I'll get an update on your reported vulnerability and it's patched I'll let you know.
Please let me know if you have any questions or concerns.

Quoted 26 lines · On Mon Jul 29 12:42:56 2019, [email protected] wrote:

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.

---
drivers/block/nbd.c | 5 +++++

1 file changed, 5 insertions(+)
drivers/block/nbd.c +5 -0
index 9bcde2325893..2410812d1e82 100644
@@ -2149,6 +2149,11 @@ static int nbd_genl_status(struct sk_buff *skb,
 struct genl_info *info)
 }
 
 dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+ if (!dev_list) {
+ ret = -EMSGSIZE;
+ goto out;
+ }
+
 if (index == -1) {
 ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
Quoted 1 line

if (ret) {

--
Best Regards,
Dhananjay Arunesh, Red Hat Product Security
7F45 FDD1 BB92 2DA8 CD05 F034 9B3D 8FE3 50EC 5D74

Reviewed-by on v2 1/1
#4 lore raw
In reply to Navid Emamdoost
Quoted 16 lines · Navid Emamdoost

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.

---
 drivers/block/nbd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/block/nbd.c +0 -0
index 9bcde2325893..2410812d1e82 100644
@@ -2149,6 +2149,11 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2159

Quoted 10 lines
drivers/block/nbd.c +5 -0
 
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+	if (!dev_list) {
+		ret = -EMSGSIZE;
+		goto out;
+	}
+
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {

Looks good to me.

#5 lore raw
In reply to Navid Emamdoost

(Just stumbled upon this patch when link to it came with a CVE bug report.)

Quoted 16 lines · Navid Emamdoost

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.

---
 drivers/block/nbd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/block/nbd.c +0 -0
index 9bcde2325893..2410812d1e82 100644
@@ -2149,6 +2149,11 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2159

Quoted 10 lines
drivers/block/nbd.c +5 -0
 
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+	if (!dev_list) {
+		ret = -EMSGSIZE;
+		goto out;
+	}
+
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {

You should also call nlmsg_free(reply) when you bail out so that you don't introduce a memory leak.

Michal Kubecek

#6 lore raw

PATCH v3 1/1 nbd_genl_status: null check for nla_nest_start

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.
v3 Update: added release reply, thanks to Michal Kubecek for pointing out.

---
 drivers/block/nbd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/nbd.c +6 -0
index e21d2ded732b..8a9712181c2a 100644
@@ -2149,6 +2149,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+	if (!dev_list) {
+		nlmsg_free(reply);
+		ret = -EMSGSIZE;
+		goto out;
+	}
+
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#7 lore raw
Quoted 18 lines · Navid Emamdoost

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.
v3 Update: added release reply, thanks to Michal Kubecek for pointing out.

---
 drivers/block/nbd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/nbd.c +0 -0
index e21d2ded732b..8a9712181c2a 100644
@@ -2149,6 +2149,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}
 

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2160

Quoted 10 lines
drivers/block/nbd.c +6 -0
 	dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+	if (!dev_list) {
+		nlmsg_free(reply);
+		ret = -EMSGSIZE;
+		goto out;
+	}
+
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {
#8 lore raw

From: Michal Kubecek <[email protected]>

Hi,

I found that CVE-2019-16089 still exist in upstream kernel. Does anyone know why this patch was not merged?

#9 lore raw
In reply to Michal Kubecek

Hi Michal, please check v3 at https://lore.kernel.org/patchwork/patch/1126650/

Thanks,
Navid.

Quoted 35 lines · Michal Kubecek

(Just stumbled upon this patch when link to it came with a CVE bug report.)

Quoted 16 lines · Navid Emamdoost

nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code.
Update: removed extra new line.

---
 drivers/block/nbd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/block/nbd.c +0 -0
index 9bcde2325893..2410812d1e82 100644
@@ -2149,6 +2149,11 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
      }

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2159

Quoted 10 lines
drivers/block/nbd.c +5 -0
 
      dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
+     if (!dev_list) {
+             ret = -EMSGSIZE;
+             goto out;
+     }
+
      if (index == -1) {
              ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
              if (ret) {

You should also call nlmsg_free(reply) when you bail out so that you don't introduce a memory leak.

Michal Kubecek

Signature · 1 line
Navid.
#10 lore raw

Hi Navid,

Not sure if you meant to cc [email protected] on this. If anything is needed from our side please let us know!

Quoted 36 lines · On Wed Oct 16 22:17:42 2019, [email protected] wrote:

Hi Michal, please check v3 at
https://lore.kernel.org/patchwork/patch/1126650/

Thanks,
Navid.

Quoted 2 lines · Michal Kubecek

(Just stumbled upon this patch when link to it came with a CVE bug

report.)

Quoted 3 lines · Navid Emamdoost
Quoted 1 line

nla_nest_start may fail and return NULL. The check is inserted,

and

Quoted 1 line
Quoted 1 line

errno is selected based on other call sites within the same source

code.

Quoted 8 lines
Quoted 8 lines

Update: removed extra new line.

---
drivers/block/nbd.c | 5 +++++

1 file changed, 5 insertions(+)
Quoted 5 lines

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff

Quoted 5 lines
drivers/block/nbd.c +0 -0
index 9bcde2325893..2410812d1e82 100644
@@ -2149,6 +2149,11 @@ static int nbd_genl_status(struct sk_buff

*skb, struct genl_info *info)

Quoted 3 lines

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff · line 2151

Quoted 3 lines
drivers/block/nbd.c +0 -0
 }
 
 dev_list = nla_nest_start_noflag(reply,

NBD_ATTR_DEVICE_LIST);

Quoted 17 lines
Quoted 7 lines

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)

Quoted 7 lines
drivers/block/nbd.c +5 -0
+ if (!dev_list) {
+ ret = -EMSGSIZE;
+ goto out;
+ }
+
 if (index == -1) {
 ret = idr_for_each(&nbd_index_idr, &status_cb,

reply);

Quoted 6 lines

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2159

Quoted 1 line
drivers/block/nbd.c +0 -0
 if (ret) {

You should also call nlmsg_free(reply) when you bail out so that you don't introduce a memory leak.

Michal Kubecek

--
Kat Bost
Red Hat Product Security