From: Jiri Kosina <jkosina@suse.cz>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] mm/sl[aou]b: make kfree() aware of error pointers
Date: Wed, 10 Sep 2014 16:24:37 +0200 (CEST) [thread overview]
Message-ID: <alpine.LNX.2.00.1409101613500.5523@pobox.suse.cz> (raw)
In-Reply-To: <20140910140759.GC31903@thunk.org>
On Wed, 10 Sep 2014, Theodore Ts'o wrote:
> So I wouldn't be so sure that we don't have these sorts of bugs hiding
> somewhere; and it's extremely easy for them to sneak in. That being
> said, I'm not in favor of making changes to kfree; I'd much rather
> depending on better testing and static checkers to fix them, since
> kfree *is* a hot path.
I of course have no objections to this check being added to whatever
static checker, that would be very welcome improvement.
Still, I believe that kernel shouldn't be just ignoring kfree(ERR_PTR)
happening. Would something like the below be more acceptable?
From: Jiri Kosina <jkosina@suse.cz>
Subject: [PATCH] mm/sl[aou]b: make kfree() aware of error pointers
Freeing if ERR_PTR is not covered by ZERO_OR_NULL_PTR() check already
present in kfree(), but it happens in the wild and has disastrous effects.
Issue a warning and don't proceed trying to free the memory if
CONFIG_DEBUG_SLAB is set.
Inspired by a9cfcd63e8d ("ext4: avoid trying to kfree an ERR_PTR pointer").
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
mm/slab.c | 6 ++++++
mm/slob.c | 7 ++++++-
mm/slub.c | 7 ++++++-
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/mm/slab.c b/mm/slab.c
index a467b30..6f49d6b 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3612,6 +3612,12 @@ void kfree(const void *objp)
trace_kfree(_RET_IP_, objp);
+#ifdef CONFIG_DEBUG_SLAB
+ if (unlikely(IS_ERR(objp))) {
+ WARN(1, "trying to free ERR_PTR\n");
+ return;
+ }
+#endif
if (unlikely(ZERO_OR_NULL_PTR(objp)))
return;
local_irq_save(flags);
diff --git a/mm/slob.c b/mm/slob.c
index 21980e0..66422a0 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -488,7 +488,12 @@ void kfree(const void *block)
struct page *sp;
trace_kfree(_RET_IP_, block);
-
+#ifdef CONFIG_DEBUG_SLAB
+ if (unlikely(IS_ERR(block))) {
+ WARN(1, "trying to free ERR_PTR\n");
+ return;
+ }
+#endif
if (unlikely(ZERO_OR_NULL_PTR(block)))
return;
kmemleak_free(block);
diff --git a/mm/slub.c b/mm/slub.c
index 3e8afcc..21155ae 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3337,7 +3337,12 @@ void kfree(const void *x)
void *object = (void *)x;
trace_kfree(_RET_IP_, x);
-
+#ifdef CONFIG_DEBUG_SLAB
+ if (unlikely(IS_ERR(x))) {
+ WARN(1, "trying to free ERR_PTR\n");
+ return;
+ }
+#endif
if (unlikely(ZERO_OR_NULL_PTR(x)))
return;
--
Jiri Kosina
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-09-10 14:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-09 21:25 Jiri Kosina
2014-09-09 23:21 ` Andrew Morton
2014-09-10 5:05 ` Jiri Kosina
2014-09-10 5:11 ` Andrew Morton
2014-09-10 6:36 ` Dan Carpenter
2014-09-10 13:56 ` Theodore Ts'o
2014-09-10 14:27 ` Dave Jones
2014-09-10 14:07 ` Theodore Ts'o
2014-09-10 14:24 ` Jiri Kosina [this message]
2014-09-10 14:33 ` Andrey Ryabinin
2014-09-10 14:42 ` Jiri Kosina
2014-09-10 15:43 ` Christoph Lameter
2014-09-10 14:26 ` Jiri Kosina
2014-09-10 15:21 ` Dan Carpenter
2014-09-10 15:28 ` Jiri Kosina
2014-09-10 15:53 ` Dan Carpenter
2014-09-10 19:40 ` Theodore Ts'o
2014-09-11 14:14 ` Rasmus Villemoes
2014-09-10 14:22 ` Christoph Lameter
2014-09-10 5:15 ` Valdis.Kletnieks
2014-09-10 6:51 ` Dan Carpenter
2014-09-10 13:59 ` Christoph Lameter
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=alpine.LNX.2.00.1409101613500.5523@pobox.suse.cz \
--to=jkosina@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=dan.carpenter@oracle.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=tytso@mit.edu \
/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