* [PATCH] slab: Fix misplaced __free_one()
@ 2020-06-26 20:07 Kees Cook
2020-06-26 20:56 ` Randy Dunlap
2020-06-29 8:10 ` Stephen Rothwell
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2020-06-26 20:07 UTC (permalink / raw)
To: akpm
Cc: Randy Dunlap, broonie, mhocko, sfr, linux-next, linux-fsdevel,
linux-mm, linux-kernel, mm-commits
The implementation of __free_one() was accidentally placed inside a
CONFIG_NUMA #ifdef. Move it above.
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Link: https://lore.kernel.org/lkml/7ff248c7-d447-340c-a8e2-8c02972aca70@infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
This a fix for slab-add-naive-detection-of-double-free.patch
---
mm/slab.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/mm/slab.c b/mm/slab.c
index bbff6705ab2b..5ccb151a6e8f 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -588,6 +588,16 @@ static int transfer_objects(struct array_cache *to,
return nr;
}
+/* &alien->lock must be held by alien callers. */
+static __always_inline void __free_one(struct array_cache *ac, void *objp)
+{
+ /* Avoid trivial double-free. */
+ if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) &&
+ WARN_ON_ONCE(ac->avail > 0 && ac->entry[ac->avail - 1] == objp))
+ return;
+ ac->entry[ac->avail++] = objp;
+}
+
#ifndef CONFIG_NUMA
#define drain_alien_cache(cachep, alien) do { } while (0)
@@ -749,16 +759,6 @@ static void drain_alien_cache(struct kmem_cache *cachep,
}
}
-/* &alien->lock must be held by alien callers. */
-static __always_inline void __free_one(struct array_cache *ac, void *objp)
-{
- /* Avoid trivial double-free. */
- if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) &&
- WARN_ON_ONCE(ac->avail > 0 && ac->entry[ac->avail - 1] == objp))
- return;
- ac->entry[ac->avail++] = objp;
-}
-
static int __cache_free_alien(struct kmem_cache *cachep, void *objp,
int node, int page_node)
{
--
2.25.1
--
Kees Cook
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] slab: Fix misplaced __free_one()
2020-06-26 20:07 [PATCH] slab: Fix misplaced __free_one() Kees Cook
@ 2020-06-26 20:56 ` Randy Dunlap
2020-06-29 8:10 ` Stephen Rothwell
1 sibling, 0 replies; 3+ messages in thread
From: Randy Dunlap @ 2020-06-26 20:56 UTC (permalink / raw)
To: Kees Cook, akpm
Cc: broonie, mhocko, sfr, linux-next, linux-fsdevel, linux-mm,
linux-kernel, mm-commits
On 6/26/20 1:07 PM, Kees Cook wrote:
> The implementation of __free_one() was accidentally placed inside a
> CONFIG_NUMA #ifdef. Move it above.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Link: https://lore.kernel.org/lkml/7ff248c7-d447-340c-a8e2-8c02972aca70@infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Thanks.
> ---
> This a fix for slab-add-naive-detection-of-double-free.patch
> ---
> mm/slab.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/mm/slab.c b/mm/slab.c
> index bbff6705ab2b..5ccb151a6e8f 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -588,6 +588,16 @@ static int transfer_objects(struct array_cache *to,
> return nr;
> }
>
> +/* &alien->lock must be held by alien callers. */
> +static __always_inline void __free_one(struct array_cache *ac, void *objp)
> +{
> + /* Avoid trivial double-free. */
> + if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) &&
> + WARN_ON_ONCE(ac->avail > 0 && ac->entry[ac->avail - 1] == objp))
> + return;
> + ac->entry[ac->avail++] = objp;
> +}
> +
> #ifndef CONFIG_NUMA
>
> #define drain_alien_cache(cachep, alien) do { } while (0)
> @@ -749,16 +759,6 @@ static void drain_alien_cache(struct kmem_cache *cachep,
> }
> }
>
> -/* &alien->lock must be held by alien callers. */
> -static __always_inline void __free_one(struct array_cache *ac, void *objp)
> -{
> - /* Avoid trivial double-free. */
> - if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) &&
> - WARN_ON_ONCE(ac->avail > 0 && ac->entry[ac->avail - 1] == objp))
> - return;
> - ac->entry[ac->avail++] = objp;
> -}
> -
> static int __cache_free_alien(struct kmem_cache *cachep, void *objp,
> int node, int page_node)
> {
>
--
~Randy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] slab: Fix misplaced __free_one()
2020-06-26 20:07 [PATCH] slab: Fix misplaced __free_one() Kees Cook
2020-06-26 20:56 ` Randy Dunlap
@ 2020-06-29 8:10 ` Stephen Rothwell
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Rothwell @ 2020-06-29 8:10 UTC (permalink / raw)
To: Kees Cook
Cc: akpm, Randy Dunlap, broonie, mhocko, linux-next, linux-fsdevel,
linux-mm, linux-kernel, mm-commits
[-- Attachment #1: Type: text/plain, Size: 474 bytes --]
Hi Kees,
On Fri, 26 Jun 2020 13:07:53 -0700 Kees Cook <keescook@chromium.org> wrote:
>
> The implementation of __free_one() was accidentally placed inside a
> CONFIG_NUMA #ifdef. Move it above.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Link: https://lore.kernel.org/lkml/7ff248c7-d447-340c-a8e2-8c02972aca70@infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
I added that to linux-next for today.
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-29 20:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-26 20:07 [PATCH] slab: Fix misplaced __free_one() Kees Cook
2020-06-26 20:56 ` Randy Dunlap
2020-06-29 8:10 ` Stephen Rothwell
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 NNTP newsgroup(s).