diff mbox series

[6/6] backports: genetlink: avoid NULL dereference

Message ID 20190315143318.4714-7-luca@coelho.fi (mailing list archive)
State Accepted
Headers show
Series backport: some patches from our internal tree 2019-03-15 | expand

Commit Message

Luca Coelho March 15, 2019, 2:33 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

If we fail to allocate extack, we fall back to the code path
that tries to send an error *with* extack, but that will
access our extack pointer. It also doesn't make sense, so just
return an error back to netlink immediately and let it handle
sending the error message to userspace.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
 backport/compat/backport-genetlink.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/backport/compat/backport-genetlink.c b/backport/compat/backport-genetlink.c
index 71bf45adf88d..885f17568333 100644
--- a/backport/compat/backport-genetlink.c
+++ b/backport/compat/backport-genetlink.c
@@ -157,12 +157,10 @@  static int backport_pre_doit(__genl_const struct genl_ops *ops,
 #if LINUX_VERSION_IS_LESS(4,12,0)
 	struct netlink_ext_ack *extack = kzalloc(sizeof(*extack), GFP_KERNEL);
 
-	__bp_genl_info_userhdr_set(info, extack);
+	if (!extack)
+		return -ENOMEM;
 
-	if (!extack) {
-		err = -ENOMEM;
-		goto err;
-	}
+	__bp_genl_info_userhdr_set(info, extack);
 
 	extack->__bp_doit = ops->doit;
 #else
@@ -175,7 +173,6 @@  static int backport_pre_doit(__genl_const struct genl_ops *ops,
 		err = family->pre_doit(ops, skb, info);
 
 #if LINUX_VERSION_IS_LESS(4,12,0)
-err:
 	if (err) {
 		/* signal to do nothing */
 		extack->__bp_doit = NULL;