From patchwork Sat May 5 06:31:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 10381993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6FED060236 for ; Sat, 5 May 2018 06:39:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FEF2295AD for ; Sat, 5 May 2018 06:39:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40C4C295BA; Sat, 5 May 2018 06:39:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF81D295AD for ; Sat, 5 May 2018 06:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750765AbeEEGjb (ORCPT ); Sat, 5 May 2018 02:39:31 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:35964 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750744AbeEEGjb (ORCPT ); Sat, 5 May 2018 02:39:31 -0400 X-Greylist: delayed 459 seconds by postgrey-1.27 at vger.kernel.org; Sat, 05 May 2018 02:39:31 EDT Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 809ADB32 for ; Sat, 5 May 2018 06:31:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K_65DqjtIO4m 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-p6.oit.umn.edu (Postfix) with ESMTPS id 55A309EF for ; Sat, 5 May 2018 01:31:51 -0500 (CDT) Received: by mail-io0-f199.google.com with SMTP id m24-v6so2183008ioh.5 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=E5QwoA/p7GrWbQxCh7gWWo1z2SiGH7nkZmcKeHTC0uadaeuZlA9YVsPxZr8ugv7630 jPGl4ubTl//eTI+QmebhVfY3qFO/GKLZUSsNvP5ansAbRH/lfEAfILZR1rO+9U/uSqxZ JIHeKSbN3dLa5ckY053QUIcgqDsGHZZNIrldcvX34X8SaCAt88snGcW3VpyMMm8Zg2TG JZi9gnG7IczMzDe2SNiBurGPIplRTUmgeaNNzKjhZgruTaZV4XfW/LkR1JygsJkOBlmt kP//ddwnRgVK0Dny78RoVYES97ZNQDsX03CiMhZBmeOnJ3uQjsQQg6drOMGQxFTjXc8T lrnQ== X-Gm-Message-State: ALQs6tCnT7WZMWeeqFWQlM+O7lrLce7jlRMIN8hvPAF5hXXB49LwBgx3 Ng8Nl6G1+wN2KnnMOo2w0350Vgcj+djZ1SiCxg9rh4ii0t7BkWBfA9OIXkZdvzYIfknV2iBda3a kTwDuxjgE7U1kqjJOwmIIw1vAww== X-Received: by 2002:a6b:6708:: with SMTP id b8-v6mr7731479ioc.178.1525501910937; Fri, 04 May 2018 23:31:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoxucysB60diXS5v9bTKMzh5FsgUzE4wrmJ0V+X5ok9ul8mccs4CMMaZpnb80h37RuGKEfokA== 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-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);