Received: by 10.192.165.148 with SMTP id m20csp4001183imm; Tue, 8 May 2018 00:53:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpov2gFvL6rWz0/e2Ztox4ISIJIledbVjdFfa9omiATY/17PoVLiPFmu6JXz5RKCc/pnDKi X-Received: by 10.98.163.21 with SMTP id s21mr39362008pfe.168.1525765997516; Tue, 08 May 2018 00:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525765997; cv=none; d=google.com; s=arc-20160816; b=jSFz9T7S/5DhRmXkztUVKFjKu4GTIBFKURdXUqsYFErlCIr0HMlPTBHz3wpnBuTOI2 jX0R2lcLGF1RJ3q3BxAFyue/Qy/2NB/Yj218itnh2Q9dUQv2FYbRkQZsFHltUOaAc+L6 IwKVBqI2O5qtW/NXsmgdWM88El3M2dejGWOXbv920CyJpto+/GysT9eIDqyVdG0RoLgu 9i9NNpEXXiJZItZCHdLYsCYKDVUtyPL6h0+57Ll+/tHtlfoq9735wHq7C8BoTqzJbA+/ OYJ8PdRUCtO5UYrSREi6PgccR3jCSXlB+81RW9kQBCBCkhQp+lpi/xEcLKdLRp09pIAr gI8A== 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=JX8TuzwizVhrsXxc7mfj/nXgIIPmiWejEiAHmzYkrGo=; b=t4OiqGkm7x5/Y/0NAVhc7RgK484YItc6i4C4aBaJEHVewN1GxOw949rFb7zxhGNe2m iX1SWALa5vMxPWr3mCPPCKOVBsX2AfA/03qQfGzhPntm6UZnL07r+h0ppQkCjS4W3Rt4 OSxVrYcnsOvUIFQrb4WWxnK0FuDHRr5+E54DlgOa8I0MJwFrn9s5ayg1ptk990lpYd4x FlUlYa/8Eg2m4FSJZXG8KAV9Emmf1RXy8jxcJMfzzHC+W3Vkp5Q/HcV3kY4SOnLDjsAd wUho15dtEOLv7NBbKy4XFuQ9xQHtkGRQknSLCWst8Rk2Cmx4q67fUXas7+1c7oq20SqC 3n/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Zu8I9BjS; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k84si2237477pfh.62.2018.05.08.00.53.01; Tue, 08 May 2018 00:53:17 -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=@gmail.com header.s=20161025 header.b=Zu8I9BjS; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754793AbeEHHrz (ORCPT + 99 others); Tue, 8 May 2018 03:47:55 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.17.0