linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch] slub: Fix a missing-check bug in mm/slub.c file of Linux 5.1.1
@ 2019-05-15  6:44 Gen Zhang
  2019-05-19  4:43 ` David Rientjes
  0 siblings, 1 reply; 3+ messages in thread
From: Gen Zhang @ 2019-05-15  6:44 UTC (permalink / raw)
  To: rientjes, iamjoonsoo.kim; +Cc: linux-kernel

Pointer s is allocated with kmem_cache_zalloc(). And s is used in the 
follwoing codes. However, when kmem_cache_zalloc fails, using s will
cause null pointer dereference and the kernel will go wrong. Thus we 
check whether the kmem_cache_zalloc fails.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>

---
--- mm/slub.c
+++ mm/slub.c
@@ -4201,6 +4201,8 @@ static struct kmem_cache * __init bootst
 {
 	int node;
 	struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
+	if (!s)
+		return ERR_PTR(-ENOMEM);
 	struct kmem_cache_node *n;
 
 	memcpy(s, static_cache, kmem_cache->object_size);
---

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch] slub: Fix a missing-check bug in mm/slub.c file of Linux 5.1.1
  2019-05-15  6:44 [Patch] slub: Fix a missing-check bug in mm/slub.c file of Linux 5.1.1 Gen Zhang
@ 2019-05-19  4:43 ` David Rientjes
  0 siblings, 0 replies; 3+ messages in thread
From: David Rientjes @ 2019-05-19  4:43 UTC (permalink / raw)
  To: Gen Zhang; +Cc: iamjoonsoo.kim, linux-kernel

On Wed, 15 May 2019, Gen Zhang wrote:

> Pointer s is allocated with kmem_cache_zalloc(). And s is used in the 
> follwoing codes. However, when kmem_cache_zalloc fails, using s will
> cause null pointer dereference and the kernel will go wrong. Thus we 
> check whether the kmem_cache_zalloc fails.
> 
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> 

It's ok if we encounter a NULL pointer dereference here, if we are ENOMEM 
then there is no way to initialize the slub allocator to be able to 
perform any future memory allocation.  Returning an error code won't help.

> ---
> --- mm/slub.c
> +++ mm/slub.c
> @@ -4201,6 +4201,8 @@ static struct kmem_cache * __init bootst
>  {
>  	int node;
>  	struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
> +	if (!s)
> +		return ERR_PTR(-ENOMEM);
>  	struct kmem_cache_node *n;
>  
>  	memcpy(s, static_cache, kmem_cache->object_size);

It's not legal to mix declarations within the C code here.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Patch] slub: Fix a missing-check bug in mm/slub.c file of Linux 5.1.1
@ 2019-05-13 14:18 Gen Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Gen Zhang @ 2019-05-13 14:18 UTC (permalink / raw)
  To: cl, penberg; +Cc: linux-kernel

Pointer s is allocated with kmem_cache_zalloc(). And s is used in the 
follwoing codes. However, when kmem_cache_zalloc fails, using s will
cause null pointer dereference and the kernel will go wrong. Thus we 
check whether the kmem_cache_zalloc fails.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>

---
--- mm/slub.c
+++ mm/slub.c
@@ -4201,6 +4201,8 @@ static struct kmem_cache * __init bootst
 {
 	int node;
 	struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
+	if (!s)
+		return ERR_PTR(-ENOMEM);
 	struct kmem_cache_node *n;
 
 	memcpy(s, static_cache, kmem_cache->object_size);
---

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-19 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-15  6:44 [Patch] slub: Fix a missing-check bug in mm/slub.c file of Linux 5.1.1 Gen Zhang
2019-05-19  4:43 ` David Rientjes
  -- strict thread matches above, loose matches on Subject: below --
2019-05-13 14:18 Gen Zhang

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).