Received: by 10.192.165.148 with SMTP id m20csp866455imm; Fri, 4 May 2018 23:32:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrfrXpgkXKxisCJCUsxR9ajLCL3Xwe+SrN5IU6CeoMqEAWxEE3jndQBVsbA9YjscabpqSbf X-Received: by 2002:a17:902:30a3:: with SMTP id v32-v6mr30867833plb.123.1525501948196; Fri, 04 May 2018 23:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525501948; cv=none; d=google.com; s=arc-20160816; b=KY1MnBJG7VFBVE5R72M36F6LwpXzXylTnT7mQ/HCpfTLIi27cAe2e4beGGUNn6bU2Q A0uO662FQG+5zjf4FXY4WwvN49UeYan9DhYDRdPR8+0NRdmSskswdqziGS1qdbYMjIK8 NGU6bw6KMddzFI4UvpadbLdWRtlHTmZjJqluDMZdeT+Lyka9AlxGzY5A7Qf+/UhayGTw vvkebiF3s2OA3RTzcBTFb9WRzMDfq9Kgv0JIBRUAWJVpQ07frVl0jDcPhIdXGtfFgtyx 1ChbvD4CaNEjy6EET30qAu8xo7nF5Fr0f730fmy3dv3TA7c8RgZSzLNcZ9UynFQe92hu PHNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=om36MWx1qgc6tA2JIjJXsKSjbrhi0pN3pJuT1Es5Bh4=; b=jJnOH9gMZPXe1i5yM05X2/KikSz/kArahYP7P6eCiLep6fxK24P3UiFZ8DUUj4psuJ RV1vevcj3QA6vIqeaEJknaWy9WxsgjCYpkn+/cfyw+IFV8W8mv+9PPDx/h/9cuahA0aY lAb8avO17bWKl85MJhMVClK/PXhoUorELaAnHuzcVwZQplFq3mp81Gt9gFqeqso9g/JC n5c+NHrrOpYNiS9ViHHTg8siacBLpnCgyZAAOs3l7KMQY1ZsaI8U5xfFFqwKbtidpaIJ Tk5ABXG3dkCB9A1p7uOuQTUJ2v/zYJ3/ITXXnr32pzxK+thhbWPDJOEFyXONL8dkRVcC HjpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=JbH3l3jp; 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=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si17193832plh.22.2018.05.04.23.32.01; Fri, 04 May 2018 23:32:28 -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=@umn.edu header.s=google header.b=JbH3l3jp; 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=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751057AbeEEGbx (ORCPT + 99 others); Sat, 5 May 2018 02:31:53 -0400 Received: from mta-p5.oit.umn.edu ([134.84.196.205]:34172 "EHLO mta-p5.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750764AbeEEGbw (ORCPT ); Sat, 5 May 2018 02:31:52 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p5.oit.umn.edu (Postfix) with ESMTP id 860ABC15 for ; Sat, 5 May 2018 06:31:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p5.oit.umn.edu ([127.0.0.1]) by localhost (mta-p5.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hJGBNRGa6DpC for ; Sat, 5 May 2018 01:31:51 -0500 (CDT) Received: from mail-io0-f199.google.com (mail-io0-f199.google.com [209.85.223.199]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p5.oit.umn.edu (Postfix) with ESMTPS id 5896EC16 for ; Sat, 5 May 2018 01:31:51 -0500 (CDT) Received: by mail-io0-f199.google.com with SMTP id f20-v6so21920906ioc.8 for ; Fri, 04 May 2018 23:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=om36MWx1qgc6tA2JIjJXsKSjbrhi0pN3pJuT1Es5Bh4=; b=JbH3l3jpCLcuLAOvnV5C0przZaMGtHfKybp1mrIzaIpgrg4zbYQH8X78JXyasYwFwU HHwzShkNH1mDzCTrO8YnNOYTNZPFYbPJW60psi/AxglLM5sJ3WyIYrH6PK8uEmjz0Uyr EMV9yfYLAALignFjYWTi4VhB+yYVbp9NIYhrSl7VpLRNTMbUZgWKA7rfO1qNu3P8qb+k 4LBdEHz+cMoLY3vUgriBmo2DVPd/6kYDjZ3tJasayFnX2cFbpVnAwNM1XdtXIl8dMpuy tFddd/c3HoQrMZvG7NbIpT/3S/cMfFNQWQE48hvt6SS8p9eagKeQODLPGEmza4tPXo6G Zyeg== 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; bh=om36MWx1qgc6tA2JIjJXsKSjbrhi0pN3pJuT1Es5Bh4=; b=WltNbX82FCw9orxRnjOdwWixtmqDM4+30nsQejCDmdV2oF08GPNJL27dv00XanHRnN 8pm4WzW3AG3HXS+2ewB+30ImUA8Tcpqcql1Lyp9HIA17haz8CI6cjlJjji1xMZuRllyd leEeDRxxs7MLWaxBzW4HqJGH9vaDJfvg0MGVKjmUoBdtwzkTETUdXuozA6T4AZITMpV5 OhQm22HFPQIl+muuDv/8f6IZf+d9gqrCo46/hrton/GRThA1jmTwe7TWwMI1ZOGEpjmm +zHqUrd/nRWjy8B0aa9RLj/ipniPjGooXJqN99d4ybIuyfiGxqnDGeI90MvP1pWtnLT2 3dnQ== X-Gm-Message-State: ALQs6tAORgV9HOk4oj03tFH4jAVoacUdpC9twWbHFHwtEVUf13cgNaSo jr2vS/nyZD2PFR91SgxSAj3Z/59bTMXVLIOHajKdIM+x/1ZnR+hp0tJLxVS8uyGsmJnjrnzkS5l fMhyRo0JjZnELgHqT0MzsTwnpOvnv X-Received: by 2002:a6b:6708:: with SMTP id b8-v6mr7731481ioc.178.1525501910937; Fri, 04 May 2018 23:31:50 -0700 (PDT) X-Received: by 2002:a6b:6708:: with SMTP id b8-v6mr7731468ioc.178.1525501910754; Fri, 04 May 2018 23:31:50 -0700 (PDT) Received: from cs-u-cslp16.cs.umn.edu (cs-u-cslp16.cs.umn.edu. [134.84.121.95]) by smtp.gmail.com with ESMTPSA id f125-v6sm1830161ita.22.2018.05.04.23.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 May 2018 23:31:49 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Kangjie Lu , Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , "James E.J. Bottomley" , "Martin K. Petersen" , MPT-FusionLinux.pdl@broadcom.com (open list:LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)), linux-scsi@vger.kernel.org (open list:LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] scsi: mpt3sas: fix a missing-check bug Date: Sat, 5 May 2018 01:31:35 -0500 Message-Id: <1525501896-8235-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In _ctl_ioctl_main(), 'ioctl_header' is first copied from the userspace pointer 'arg'. 'ioctl_header.ioc_number' is then verified by _ctl_verify_adapter(). If the verification is failed, an error code -ENODEV is returned. Otherwise, the verification result, i.e., the MPT3SAS adapter that matches with the 'ioctl_header.ioc_number', is saved to 'ioc'. Later on, if the 'cmd' is MPT3COMMAND, the whole ioctl command struct is copied again from the userspace pointer 'arg' and saved to 'karg'. Then the function _ctl_do_mpt_command() is invoked to execute the command with the adapter 'ioc' and 'karg' as inputs. Given that the pointer 'arg' resides in userspace, a malicious userspace process can race to change the 'ioc_number' between the two copies, which will cause inconsistency issues, potentially security issues since an inconsistent adapter could be used with the command struct 'karg' as inputs of _ctl_do_mpt_command(). Moreover, the user can potentially provide a valid 'ioc_number' to pass the verification, and then modify it to an invalid 'ioc_number'. That means, an invalid 'ioc_number' can potentially bypass the verification check. To fix this issue, we need to recheck the 'ioc_number' copied after the second copy to make sure it is not changed since the first copy. Signed-off-by: Wenwen Wang --- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index d3cb387..0c140c7 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -2388,6 +2388,11 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg, break; } + if (karg.hdr.ioc_number != ioctl_header.ioc_number) { + ret = -EINVAL; + break; + } + if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) { uarg = arg; ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf); -- 2.7.4