From patchwork Tue May 8 07:47:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 10385503 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 ACF0660353 for ; Tue, 8 May 2018 07:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94568285E8 for ; Tue, 8 May 2018 07:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8929628622; Tue, 8 May 2018 07:48:09 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 3E186285E8 for ; Tue, 8 May 2018 07:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754758AbeEHHry (ORCPT ); Tue, 8 May 2018 03:47:54 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34358 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754599AbeEHHrx (ORCPT ); Tue, 8 May 2018 03:47:53 -0400 Received: by mail-pf0-f195.google.com with SMTP id a14so23576789pfi.1; Tue, 08 May 2018 00:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=JX8TuzwizVhrsXxc7mfj/nXgIIPmiWejEiAHmzYkrGo=; b=Zu8I9BjS81VJgVWRh7+71jVivhGxWOZ6ZBXnQVQUcK1TThAsT8MbXL3GiTz1a52SPo /2a6CdRC+p+PmJgaJu/Akg/tib7aX5tdgu3yZrlLyr6pbs/o5Qbec7xJPKGDBbHCkRRp fCReHJ9+eoIyd4G+Hl9WQ1OOwziq81ZThX/FqBZTXInUwGEf0hZ3Xhh+ttcSxhN+/npI tlgH7SRZ2qo9uueLWHjgHEPNw+Kgarj1bEXf3ZaoMWmiQROunzaubBN7WWSJEqpH2bLW xKF5rVnndYSYrsFl+c1VmMIkMGvJe4r8YiqQ6enXkpMIOxa3vHZtK7CoWGVlOy1U08GX j8lQ== 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=JX8TuzwizVhrsXxc7mfj/nXgIIPmiWejEiAHmzYkrGo=; b=GZct8SGXYibB305Yb6d+iytuOiksNQ7lj4XI6Ym3o7trj2fctJ/vLMrzU5tLLtl5Sf qC/Kr5Iqe1K5SRTxrovNYmj9FoHQGru4p3E4Dy9r6EWCEvIrAfujZmihHc4P8e2yVjyT 5HPxc//E1CQ89oIDIJSUWfg4SWTaVFYPHEVV34ATOBUX5X1reOa4lJVomMx/7IgQ58Pq zDsY/GxCYA/pP9CAfyuqb4Lu3MQUSlwm09d8iFYSiyLL3cDDdPCc2UcmXlndNvAJ+Mpl iAjLOmRZ+57YisSsjMIFzvDN389bGF09B61OvH5skaR1AFfR5Gl0Lriapdse+Ku/2xrv LvPg== X-Gm-Message-State: ALQs6tDs48IH2aKLlg7WBXEaVNsktm5nq5HLHBbH2/nat4/yQ23h8v+5 jOFQqccEsZe7r9Fuuhc2++8= X-Google-Smtp-Source: AB8JxZpVq6R4TQsrpiemqIygGX9Zq5TY0l4ln6T41eAzzJ4AYZ4UuYX+eHhWFPWOqkpaXyiQGCywtg== X-Received: by 2002:a63:9511:: with SMTP id p17-v6mr13885462pgd.132.1525765672640; Tue, 08 May 2018 00:47:52 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:1:4413:9049:25cd:b90:73a0]) by smtp.gmail.com with ESMTPSA id c83sm22397236pfc.111.2018.05.08.00.47.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 00:47:52 -0700 (PDT) From: Jia-Ju Bai To: oneukum@suse.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-scsi@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] usb: storage: Fix a possible data race in uas_queuecommand_lck Date: Tue, 8 May 2018 15:47:43 +0800 Message-Id: <20180508074743.13622-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The write operations to "cmnd->result" and "cmnd->scsi_done" are protected by the lock on line 642-643, but the write operations to these data on line 634-635 are not protected by the lock. Thus, there may exist a data race for "cmnd->result" and "cmnd->scsi_done". To fix this data race, the write operations on line 634-635 should be also protected by the lock. Signed-off-by: Jia-Ju Bai Nacked-by: Oliver Neukum --- drivers/usb/storage/uas.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 6034c39b67d1..dde7a43ad491 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -627,17 +627,18 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, if (cmnd->device->host->host_self_blocked) return SCSI_MLQUEUE_DEVICE_BUSY; + spin_lock_irqsave(&devinfo->lock, flags); + if ((devinfo->flags & US_FL_NO_ATA_1X) && (cmnd->cmnd[0] == ATA_12 || cmnd->cmnd[0] == ATA_16)) { memcpy(cmnd->sense_buffer, usb_stor_sense_invalidCDB, sizeof(usb_stor_sense_invalidCDB)); cmnd->result = SAM_STAT_CHECK_CONDITION; cmnd->scsi_done(cmnd); + spin_unlock_irqrestore(&devinfo->lock, flags); return 0; } - spin_lock_irqsave(&devinfo->lock, flags); - if (devinfo->resetting) { cmnd->result = DID_ERROR << 16; cmnd->scsi_done(cmnd);