Backports Archive mirror
 help / color / mirror / Atom feed
From: Luca Coelho <luca@coelho.fi>
To: backports@vger.kernel.org
Cc: Luca Coelho <luciano.coelho@intel.com>
Subject: [PATCH] backport: check for failure when allocating ops in genetlink
Date: Tue,  2 Apr 2019 16:08:23 +0300	[thread overview]
Message-ID: <20190402130823.13965-1-luca@coelho.fi> (raw)

From: Luca Coelho <luciano.coelho@intel.com>

We were not checking if the allocation failed in
backport_genl_register_family(), which could lead to NULL pointer
dereferences later.  Fix that.

Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
 backport/compat/backport-genetlink.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/backport/compat/backport-genetlink.c b/backport/compat/backport-genetlink.c
index 885f17568333..16971ec34e38 100644
--- a/backport/compat/backport-genetlink.c
+++ b/backport/compat/backport-genetlink.c
@@ -220,7 +220,11 @@ int backport_genl_register_family(struct genl_family *family)
 
 	/* we append one entry to the ops to find our family pointer ... */
 	ops = kzalloc(sizeof(*ops) * (family->n_ops + 1), GFP_KERNEL);
+	if (!ops)
+		return -ENOMEM;
+
 	memcpy(ops, family->ops, sizeof(*ops) * family->n_ops);
+
 	/*
 	 * Remove policy to skip validation as the struct nla_policy
 	 * memory layout isn't compatible with the old version
-- 
2.20.1

--
To unsubscribe from this list: send the line "unsubscribe backports" in

                 reply	other threads:[~2019-04-02 13:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190402130823.13965-1-luca@coelho.fi \
    --to=luca@coelho.fi \
    --cc=backports@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).