From patchwork Mon Dec 28 12:45:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 352649 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9754699jai; Mon, 28 Dec 2020 05:41:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIs7crrhUThoCCXDBNp7RpAf6PS+thXATPCFgstIbODMBANSRIbw9iubx4DYCISE113PNQ X-Received: by 2002:a17:906:134f:: with SMTP id x15mr41856293ejb.278.1609162890995; Mon, 28 Dec 2020 05:41:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609162890; cv=none; d=google.com; s=arc-20160816; b=Cx26+6GBY43tyWq4LBOj7XNCROLntpbHzgZ+J8FW+WLuJCMctwtpC5FpOnvRdyv06F eQeS7zQzxxUa/OdtQ20K0WLQW+gwwepRCzzUItqmpV35j4poYd6GPmU6aDiNbuWU/+bR ZZ1ocygOtuR5hvht9mSmxakJmkWug+GLNkNPsQB/WomsbEMhRxiEtrllDAH4lbX/7xBP 0kp+8uoVQKX0n1/jAXja7QebVwZspMO3gBpstq40e0LQbyeGBySx1jRSSSWF4R+UnhKI 1tS2l46EVxsv0oKLJwpdk+a7v9oE82rZOV9ZWi+eh36yhMJy7ySuXOvMuRG0H6Rw6/bg FZrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6ZgFOv8zTwbf8uUm5vMqtM/ghbRiPD7Xnj+NCs0ui+M=; b=r7NwbbTGk/VEIGOATOmW6exdcpNOsys2Cj+5RqWu3vM9dlKXH4U0LWj046CQiaISaU SYZ6c3H8Re+BCRtN9OPRWyEmeusU7RrdBAQArDMdepMYodP9+HWVpYAMPQVU0Is0m/rE i7tXIsvpJjK7L0HaDlnpUtnVXlj1ZOTjfOb9JSzjQCM3K9iXD/PWa6HiuZwpvsOtrXzp F2mc5bD/vYtJ6g1y9J+k23ybLuMgDccQL5Xo2z1zkS2xUt4xmE0BDkwYGsNFRUnaWLfq ZMSm341ZgbEoETj9Sac9REKVl/KMmJ3ljtHjECQEBcocLWAYr8LheaVne92c4hZdQhVd KrZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1SoP5F3n; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si18283299ejt.198.2020.12.28.05.41.30; Mon, 28 Dec 2020 05:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1SoP5F3n; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403946AbgL1Nkm (ORCPT + 14 others); Mon, 28 Dec 2020 08:40:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:40964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403971AbgL1Nkl (ORCPT ); Mon, 28 Dec 2020 08:40:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9999022BF5; Mon, 28 Dec 2020 13:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609162801; bh=pmSgCVoq2MLairhTK6x22id34JRh42THxs/MAJ6h7Vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1SoP5F3nWP1sBmcv2nKtn6gIwBbIfWKd5Z4IL9HLoPuXYUHKTGuziNp3+vzhRBcZX ftOxybpral/vAmWRS166Qq5IymN/lOo+iPJqK7j/408aOFDLKLOpeuVxgMs5qTwk+T 0JwwBnkke/grDKFoRA0Phmq1SZvyRaZbX2xqmYRc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Arnd Bergmann , "Martin K. Petersen" Subject: [PATCH 5.4 065/453] scsi: megaraid_sas: Check user-provided offsets Date: Mon, 28 Dec 2020 13:45:01 +0100 Message-Id: <20201228124940.375578738@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124937.240114599@linuxfoundation.org> References: <20201228124937.240114599@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnd Bergmann commit 381d34e376e3d9d27730fda8a0e870600e6c8196 upstream. It sounds unwise to let user space pass an unchecked 32-bit offset into a kernel structure in an ioctl. This is an unsigned variable, so checking the upper bound for the size of the structure it points into is sufficient to avoid data corruption, but as the pointer might also be unaligned, it has to be written carefully as well. While I stumbled over this problem by reading the code, I did not continue checking the function for further problems like it. Link: https://lore.kernel.org/r/20201030164450.1253641-2-arnd@kernel.org Fixes: c4a3e0a529ab ("[SCSI] MegaRAID SAS RAID: new driver") Cc: # v2.6.15+ Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/megaraid/megaraid_sas_base.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -8038,7 +8038,7 @@ megasas_mgmt_fw_ioctl(struct megasas_ins int error = 0, i; void *sense = NULL; dma_addr_t sense_handle; - unsigned long *sense_ptr; + void *sense_ptr; u32 opcode = 0; memset(kbuff_arr, 0, sizeof(kbuff_arr)); @@ -8160,6 +8160,13 @@ megasas_mgmt_fw_ioctl(struct megasas_ins } if (ioc->sense_len) { + /* make sure the pointer is part of the frame */ + if (ioc->sense_off > + (sizeof(union megasas_frame) - sizeof(__le64))) { + error = -EINVAL; + goto out; + } + sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, &sense_handle, GFP_KERNEL); if (!sense) { @@ -8167,12 +8174,11 @@ megasas_mgmt_fw_ioctl(struct megasas_ins goto out; } - sense_ptr = - (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); + sense_ptr = (void *)cmd->frame + ioc->sense_off; if (instance->consistent_mask_64bit) - *sense_ptr = cpu_to_le64(sense_handle); + put_unaligned_le64(sense_handle, sense_ptr); else - *sense_ptr = cpu_to_le32(sense_handle); + put_unaligned_le32(sense_handle, sense_ptr); } /*