All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libceph, ceph: potential dereference of null pointer
@ 2021-12-09  2:50 Jiasheng Jiang
  2021-12-09 11:20 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: Jiasheng Jiang @ 2021-12-09  2:50 UTC (permalink / raw)
  To: idryomov, jlayton, davem, kuba
  Cc: ceph-devel, netdev, linux-kernel, Jiasheng Jiang

The return value of kzalloc() needs to be checked.
To avoid use of null pointer in case of the failure of alloc.

Fixes: 3d14c5d2b6e1 ("ceph: factor out libceph from Ceph file system")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 net/ceph/osd_client.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index ff8624a7c964..3203e8a34370 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1234,6 +1234,8 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
 	WARN_ON(onum == CEPH_HOMELESS_OSD);
 
 	osd = kzalloc(sizeof(*osd), GFP_NOIO | __GFP_NOFAIL);
+	if (!osd)
+		return NULL;
 	osd_init(osd);
 	osd->o_osdc = osdc;
 	osd->o_osd = onum;
-- 
2.25.1


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

* Re: [PATCH] libceph, ceph: potential dereference of null pointer
  2021-12-09  2:50 [PATCH] libceph, ceph: potential dereference of null pointer Jiasheng Jiang
@ 2021-12-09 11:20 ` Jeff Layton
  2021-12-09 12:59   ` Xiubo Li
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Layton @ 2021-12-09 11:20 UTC (permalink / raw)
  To: Jiasheng Jiang, idryomov, davem, kuba; +Cc: ceph-devel, netdev, linux-kernel

On Thu, 2021-12-09 at 10:50 +0800, Jiasheng Jiang wrote:
> The return value of kzalloc() needs to be checked.
> To avoid use of null pointer in case of the failure of alloc.
> 
> Fixes: 3d14c5d2b6e1 ("ceph: factor out libceph from Ceph file system")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  net/ceph/osd_client.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
> index ff8624a7c964..3203e8a34370 100644
> --- a/net/ceph/osd_client.c
> +++ b/net/ceph/osd_client.c
> @@ -1234,6 +1234,8 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
>  	WARN_ON(onum == CEPH_HOMELESS_OSD);
>  
>  	osd = kzalloc(sizeof(*osd), GFP_NOIO | __GFP_NOFAIL);
> +	if (!osd)
> +		return NULL;
>  	osd_init(osd);
>  	osd->o_osdc = osdc;
>  	osd->o_osd = onum;

__GFP_NOFAIL should ensure that it never returns NULL, right?

Also, if you're going to fix this up to handle that error then you
probably also need to fix lookup_create_osd to handle a NULL return from
create_osd as well.
-- 
Jeff Layton <jlayton@kernel.org>

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

* Re: [PATCH] libceph, ceph: potential dereference of null pointer
  2021-12-09 11:20 ` Jeff Layton
@ 2021-12-09 12:59   ` Xiubo Li
  0 siblings, 0 replies; 3+ messages in thread
From: Xiubo Li @ 2021-12-09 12:59 UTC (permalink / raw)
  To: Jeff Layton, Jiasheng Jiang, idryomov, davem, kuba
  Cc: ceph-devel, netdev, linux-kernel


On 12/9/21 7:20 PM, Jeff Layton wrote:
> On Thu, 2021-12-09 at 10:50 +0800, Jiasheng Jiang wrote:
>> The return value of kzalloc() needs to be checked.
>> To avoid use of null pointer in case of the failure of alloc.
>>
>> Fixes: 3d14c5d2b6e1 ("ceph: factor out libceph from Ceph file system")
>> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>> ---
>>   net/ceph/osd_client.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
>> index ff8624a7c964..3203e8a34370 100644
>> --- a/net/ceph/osd_client.c
>> +++ b/net/ceph/osd_client.c
>> @@ -1234,6 +1234,8 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
>>   	WARN_ON(onum == CEPH_HOMELESS_OSD);
>>   
>>   	osd = kzalloc(sizeof(*osd), GFP_NOIO | __GFP_NOFAIL);
>> +	if (!osd)
>> +		return NULL;
>>   	osd_init(osd);
>>   	osd->o_osdc = osdc;
>>   	osd->o_osd = onum;
> __GFP_NOFAIL should ensure that it never returns NULL, right?

Yeah, from the comment, it make no sense to test for failure here:


204  * %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the 
caller
205  * cannot handle allocation failures. The allocation could block
206  * indefinitely but will never return with failure. Testing for
207  * failure is pointless.
208  * New users should be evaluated carefully (and the flag should be
209  * used only when there is no reasonable failure policy) but it is
210  * definitely preferable to use the flag rather than opencode endless
211  * loop around allocator.
212  * Using this flag for costly allocations is _highly_ discouraged.
213  */



> Also, if you're going to fix this up to handle that error then you
> probably also need to fix lookup_create_osd to handle a NULL return from
> create_osd as well.


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

end of thread, other threads:[~2021-12-09 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09  2:50 [PATCH] libceph, ceph: potential dereference of null pointer Jiasheng Jiang
2021-12-09 11:20 ` Jeff Layton
2021-12-09 12:59   ` Xiubo Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.