linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] block/rnbd: fix a null pointer dereference on dev->blk_symlink_name
@ 2020-12-07 14:54 Colin King
  2020-12-07 15:01 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2020-12-07 14:54 UTC (permalink / raw)
  To: Danil Kipnis, Jack Wang, Jens Axboe, Jason Gunthorpe,
	Bart Van Assche, linux-block
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently in the case where dev->blk_symlink_name fails to be allocates
the error return path attempts to set an end-of-string character to
the unallocated dev->blk_symlink_name causing a null pointer dereference
error. Fix this by returning with an explicity ENOMEM error (which also
is missing in the original code as was not initialized).

Addresses-Coverity: ("Dereference after null check")
Fixes: 1eb54f8f5dd8 ("block/rnbd: client: sysfs interface functions")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/block/rnbd/rnbd-clt-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index c3c96a567568..a7caeedeb198 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -499,7 +499,7 @@ static int rnbd_clt_add_dev_symlink(struct rnbd_clt_dev *dev)
 	dev->blk_symlink_name = kzalloc(len, GFP_KERNEL);
 	if (!dev->blk_symlink_name) {
 		rnbd_clt_err(dev, "Failed to allocate memory for blk_symlink_name\n");
-		goto out_err;
+		return -ENOMEM;
 	}
 
 	ret = rnbd_clt_get_path_name(dev, dev->blk_symlink_name,
-- 
2.29.2


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

* Re: [PATCH][next] block/rnbd: fix a null pointer dereference on dev->blk_symlink_name
  2020-12-07 14:54 [PATCH][next] block/rnbd: fix a null pointer dereference on dev->blk_symlink_name Colin King
@ 2020-12-07 15:01 ` Jens Axboe
  2020-12-07 15:02   ` Jinpu Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2020-12-07 15:01 UTC (permalink / raw)
  To: Colin King, Danil Kipnis, Jack Wang, Jason Gunthorpe,
	Bart Van Assche, linux-block
  Cc: kernel-janitors, linux-kernel

On 12/7/20 7:54 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently in the case where dev->blk_symlink_name fails to be allocates
> the error return path attempts to set an end-of-string character to
> the unallocated dev->blk_symlink_name causing a null pointer dereference
> error. Fix this by returning with an explicity ENOMEM error (which also
> is missing in the original code as was not initialized).

Applied, thanks.

-- 
Jens Axboe


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

* Re: [PATCH][next] block/rnbd: fix a null pointer dereference on dev->blk_symlink_name
  2020-12-07 15:01 ` Jens Axboe
@ 2020-12-07 15:02   ` Jinpu Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Jinpu Wang @ 2020-12-07 15:02 UTC (permalink / raw)
  To: Jens Axboe, Colin King
  Cc: Danil Kipnis, Jason Gunthorpe, Bart Van Assche, linux-block,
	kernel-janitors, open list

On Mon, Dec 7, 2020 at 4:01 PM Jens Axboe <axboe@kernel.dk> wrote:
>
> On 12/7/20 7:54 AM, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently in the case where dev->blk_symlink_name fails to be allocates
> > the error return path attempts to set an end-of-string character to
> > the unallocated dev->blk_symlink_name causing a null pointer dereference
> > error. Fix this by returning with an explicity ENOMEM error (which also
> > is missing in the original code as was not initialized).
>
> Applied, thanks.

Thanks Colin for the fix, and thanks Jens for taking care of this.

Jack Wang

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

end of thread, other threads:[~2020-12-07 15:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 14:54 [PATCH][next] block/rnbd: fix a null pointer dereference on dev->blk_symlink_name Colin King
2020-12-07 15:01 ` Jens Axboe
2020-12-07 15:02   ` Jinpu Wang

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