From: Dan Carpenter <dan.carpenter@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Imre Deak <imre.deak@intel.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Maxim Levitsky <maximlevitsky@gmail.com>,
Tejun Heo <tj@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [patch] lib/scatterlist: error handling in __sg_alloc_table()
Date: Thu, 20 Jun 2013 11:12:18 +0300 [thread overview]
Message-ID: <20130620081218.GC15095@elgon.mountain> (raw)
I was reviewing code which I suspected might allocate a zero size SG
table. That will cause memory corruption. Also we can't return before
doing the memset or we could end up using uninitialized memory in the
cleanup path.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index a1cf8ca..d39178b 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -247,13 +247,15 @@ int __sg_alloc_table(struct sg_table *table, unsigned int nents,
struct scatterlist *sg, *prv;
unsigned int left;
+ memset(table, 0, sizeof(*table));
+
+ if (nents == 0)
+ return -EINVAL;
#ifndef ARCH_HAS_SG_CHAIN
if (WARN_ON_ONCE(nents > max_ents))
return -EINVAL;
#endif
- memset(table, 0, sizeof(*table));
-
left = nents;
prv = NULL;
do {
reply other threads:[~2013-06-20 8:12 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=20130620081218.GC15095@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.vetter@ffwll.ch \
--cc=imre.deak@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maximlevitsky@gmail.com \
--cc=tj@kernel.org \
/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