From patchwork Thu Aug 9 13:55:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [07/13] ide: Potential null pointer dereference in ide_cmd_ioctl() Date: Thu, 09 Aug 2012 03:55:24 -0000 From: Marina Makienko X-Patchwork-Id: 176110 Message-Id: <1344520529-19164-5-git-send-email-makienko@ispras.ru> To: "David S. Miller" Cc: Marina Makienko , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@ispras.ru The function blk_get_request() can return NULL in some cases. There are checks on it if function is called with argumetns one of which is GFP_ATOMIC/GFP_NOIO/etc. If system couldn't find request blk_get_request() return NULL. But if there is function call with argument __GFP_WAIT the system will wait until get request or the queue becomes dead. If something kills the queue, blk_get_request() return NULL and next operations will lead to errors. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Marina Makienko --- drivers/ide/ide-ioctls.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c index 4d19eb9..463f0ff 100644 --- a/drivers/ide/ide-ioctls.c +++ b/drivers/ide/ide-ioctls.c @@ -126,6 +126,8 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) struct request *rq; rq = blk_get_request(drive->queue, READ, __GFP_WAIT); + if (!rq) + return err; rq->cmd_type = REQ_TYPE_ATA_TASKFILE; err = blk_execute_rq(drive->queue, NULL, rq, 0); blk_put_request(rq); @@ -222,6 +224,8 @@ static int generic_drive_reset(ide_drive_t *drive) int ret = 0; rq = blk_get_request(drive->queue, READ, __GFP_WAIT); + if (!rq) + return ret; rq->cmd_type = REQ_TYPE_SPECIAL; rq->cmd_len = 1; rq->cmd[0] = REQ_DRIVE_RESET;