Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1908655imm; Tue, 22 May 2018 11:16:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrZbO8474dCpg4rFaQwy5h7h8E7v1SEsvLnvjdJFbI3h5TtmWCBoksGWj3WVwArppoqQWZP X-Received: by 2002:a63:7848:: with SMTP id t69-v6mr20102987pgc.380.1527012964637; Tue, 22 May 2018 11:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527012964; cv=none; d=google.com; s=arc-20160816; b=mKZ1mkP5xy3dpeMyw1tO+lC2WNC01GKKLs+LvBoqZ3WkB5PX5dwK/7ZVVXeMlXOGhr YBLwen9mbNJJ6Wd1x0HefHZLaPj4mAYt7epm8A7vwyfRJQT+X8px+G2pXn97yxkSLKQm zT/VakKYfCAB+ButIUS0znqwzE9NoHexWyt+AJYfmt6rtSZYrlo5+m5LLk3bpgSEcPMG sh+4c7rxIzTnSnle1XoFDOTzpMUATBpT001OR0oze99GVg/WsiI8qvQvCI+e4D83cYqO EjZQ07V8YQZdT4/cMKe4EdpNxkVtgpubXomK3vXAgJ4htl0u+QUfJtM93Z2Sar0F2KXW HMTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=+2HQTZYPA0C48EDdQjpVt/C2s/eKEfFSDAk8hZXCMPg=; b=DWtx7wku2luwRRmFynclS6GfvYo/LJEMFO8i0rNyFHkWRwsYrriuOVRSf+1bS0R3zg cWbv2xC9/Thxi9BkgWkxdkBtiLbgzoDvTc9Xs+1yjv3+kM3rHj2FVYzIoTAc1WI9IumU 0PAlMiECw8M4AAYLtIOczJmHagjgrBb9lCdKvV0MWdKN38mJ5i6CFdmMLNTRY7gjy1B/ FV8f6scb+sLO4EWteCGjME1bWufKbh0LBOWfxqOXrkYWdK0mv6g0exxyO5sw5NDo7Cxw c8L3YdQIXiN+rmrtQrOcJFrihWHF4+m0heduqQOUok8ulbGdS8pKIhFQcF7N0VtoB6nN xf7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dnHSNVlc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e68-v6si17516826pfl.132.2018.05.22.11.15.49; Tue, 22 May 2018 11:16:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dnHSNVlc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbeEVSPh (ORCPT + 99 others); Tue, 22 May 2018 14:15:37 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:45216 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751602AbeEVSP0 (ORCPT ); Tue, 22 May 2018 14:15:26 -0400 Received: by mail-pl0-f66.google.com with SMTP id bi12-v6so11358225plb.12 for ; Tue, 22 May 2018 11:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+2HQTZYPA0C48EDdQjpVt/C2s/eKEfFSDAk8hZXCMPg=; b=dnHSNVlcPaB0kLU6E+3gsvFAXHGfqeicCFGn//AzJZY0NWRe8DRJJPqvRhyZbp+TeK Oy0XRVvz+CLpLuLEIKTONWovHhBjZ/JOJP/StBtuli45CsT2SDddP1y1OGVlPJ99i4Md KBxGqpPCBzWcJ8gO52r4xcJai2MZfS9SfZZw8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+2HQTZYPA0C48EDdQjpVt/C2s/eKEfFSDAk8hZXCMPg=; b=k8093gREEorlNfFccy+Q4ZT8uze2AydQt8HadthwzUmjM211oDnIzdrtaxJ5W0sNM3 5wfSjjLPY2mrGYuyOjBR+RpdesILl6TPj9FTRAydqCNdpFXkd/jYmf4jIb7bBLBY3dc3 mtMZSGjqMCA3r3n9mdZ7tOc+939UDvfujcdvgUfdTWaVGmUSA0lMROcLl09h4UzIRwPX KGOuh35Krw5soAmutSu2qc+0A/nIJf5BT7ix5w+QFPYr5Dj5CjIdx/4kPMcAXe1GqNMO DLaMMbiQuH2SIci0IsxlqsIvOF9PMuZGSAUe3R0cxLH0kQCihZ7PEuDX5Dvm9R7obtmF BMmw== X-Gm-Message-State: ALKqPwcIr0pdvIaB2MAejC2jOHt53xu40B7BN3Q1Fam109ELgTq0XL4p RBbUND7g78m9O0FWx2shc6trJw== X-Received: by 2002:a17:902:9344:: with SMTP id g4-v6mr26133370plp.10.1527012925549; Tue, 22 May 2018 11:15:25 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id 126-v6sm2676580pge.8.2018.05.22.11.15.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 11:15:23 -0700 (PDT) From: Kees Cook To: Jens Axboe Cc: Kees Cook , "Martin K. Petersen" , James Bottomley , Tejun Heo , Borislav Petkov , "David S. Miller" , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] libata-scsi: Move sense buffers onto stack Date: Tue, 22 May 2018 11:15:11 -0700 Message-Id: <20180522181512.39316-6-keescook@chromium.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180522181512.39316-1-keescook@chromium.org> References: <20180522181512.39316-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of dynamically allocating the sense buffers, put them on the stack so that future compile-time sizeof() checks will be able to see their buffer length. Signed-off-by: Kees Cook --- drivers/ata/libata-scsi.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 89a9d4a2efc8..3a43d3a1ce2d 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -597,8 +597,9 @@ static int ata_get_identity(struct ata_port *ap, struct scsi_device *sdev, int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) { int rc = 0; + u8 sensebuf[SCSI_SENSE_BUFFERSIZE]; u8 scsi_cmd[MAX_COMMAND_SIZE]; - u8 args[4], *argbuf = NULL, *sensebuf = NULL; + u8 args[4], *argbuf = NULL; int argsize = 0; enum dma_data_direction data_dir; struct scsi_sense_hdr sshdr; @@ -610,10 +611,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) if (copy_from_user(args, arg, sizeof(args))) return -EFAULT; - sensebuf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO); - if (!sensebuf) - return -ENOMEM; - + memset(sensebuf, 0, sizeof(sensebuf)); memset(scsi_cmd, 0, sizeof(scsi_cmd)); if (args[3]) { @@ -685,7 +683,6 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) && copy_to_user(arg + sizeof(args), argbuf, argsize)) rc = -EFAULT; error: - kfree(sensebuf); kfree(argbuf); return rc; } @@ -704,8 +701,9 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) { int rc = 0; + u8 sensebuf[SCSI_SENSE_BUFFERSIZE]; u8 scsi_cmd[MAX_COMMAND_SIZE]; - u8 args[7], *sensebuf = NULL; + u8 args[7]; struct scsi_sense_hdr sshdr; int cmd_result; @@ -715,10 +713,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) if (copy_from_user(args, arg, sizeof(args))) return -EFAULT; - sensebuf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO); - if (!sensebuf) - return -ENOMEM; - + memset(sensebuf, 0, sizeof(sensebuf)); memset(scsi_cmd, 0, sizeof(scsi_cmd)); scsi_cmd[0] = ATA_16; scsi_cmd[1] = (3 << 1); /* Non-data */ @@ -769,7 +764,6 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) } error: - kfree(sensebuf); return rc; } -- 2.17.0