block/rnbd: fix a null pointer dereference on dev->blk_symlink_name
authorColin Ian King <colin.king@canonical.com>
Mon, 7 Dec 2020 14:54:46 +0000 (14:54 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 Dec 2020 10:53:40 +0000 (11:53 +0100)
commitaa4f552aec3d43cc1455490825399d178da0a65f
tree97f451ece26bfafefdbda1e4abe359746e388066
parenta7d4dd109eae096eb38cef8a50a9c86335420a98
block/rnbd: fix a null pointer dereference on dev->blk_symlink_name

[ Upstream commit 733c15bd3a944b8eeaacdddf061759b6a83dd3f4 ]

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

Fixes: 1eb54f8f5dd8 ("block/rnbd: client: sysfs interface functions")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Addresses-Coverity: ("Dereference after null check")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/rnbd/rnbd-clt-sysfs.c