From patchwork Mon Jul 29 11:49:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 11063623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BF2A14E5 for ; Mon, 29 Jul 2019 11:49:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D2B9274D0 for ; Mon, 29 Jul 2019 11:49:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01E5828768; Mon, 29 Jul 2019 11:49:48 +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,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 9A17E274D0 for ; Mon, 29 Jul 2019 11:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387742AbfG2Ltn (ORCPT ); Mon, 29 Jul 2019 07:49:43 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:47094 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387482AbfG2Ltn (ORCPT ); Mon, 29 Jul 2019 07:49:43 -0400 Received: by mail-pf1-f195.google.com with SMTP id c3so4772434pfa.13; Mon, 29 Jul 2019 04:49:43 -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=t4LrUjq6T4dirnuW+FmcNbvRfUA+DI+0HKJt+m2bWqc=; b=eo/5Z10vJWswbhZ9Liy5f3E/5hKOoioHrjunY9OWkIDNBuYO9CPUY4Hep3kZuuOR92 /ncIb+PR8zLWvRXC8k6awPKhRgY4Qa+qQBpLG3vER8qVzic5LUM7Pi7kneKywt8AKkS3 terYnDeO56bO1rs86xancM02QDKUuh9dLzQDiTFzxTCslCHTvUPVpzAOkBtjzfgaBhtn iYLV4kE6GZzDTXXi7pKoe28TApuM4Bsd7xHbkzgqhfIWdpW44cgdqoHPVX3hBG0jz37c 3ATMEIXYebV6LRFQq77V2j+24/US12CJWXpKpvi5XbjuriwQuUZFlIw9f3vh6GakZF3i qk9A== 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=t4LrUjq6T4dirnuW+FmcNbvRfUA+DI+0HKJt+m2bWqc=; b=sWV5TtZr9iA/wM95iXdsZ53WFk1DbBAQzzgaV5d0twepgDoFkTUtgLaGvkTHnWIXaR bf8zyA148370qfHNhsLImV2/oNSYYdwe8Y/nJCyP1f6oLrEbt64p1+AVmh2eWvvqKNOn HapHRnifphf9DPReSvU6kQ4S8rSMekzWkdFSxsOU19e3EOo4WPzGHK/5WIenI138qXbe puYfUIf14TXoYiK2eHQtVwjRoYmgoVef+UO3aBSVWw1zz45xGFsgAQ8nTIE0f2YvPH88 KPsBYkfq6CQbujfezVEISi6YarL9wv4EDcBnbR9qVIB3mjl5qUA1Ei6iAcmZZkvKUUgc cJvA== X-Gm-Message-State: APjAAAXHyOonSisXabpqnSHydIRrU1tPKSaxy97dL9iQ5Elej5Rlzc1L jIhdYrUD/FHRXcjdJekBLQE= X-Google-Smtp-Source: APXvYqy33Qp2byQh79yNYIetAkyhvaxtnAn6cxcHG55JXV0s6XNNCvNvnKJUszQYhHI+enW0sLmk/A== X-Received: by 2002:a63:2252:: with SMTP id t18mr104148160pgm.5.1564400982701; Mon, 29 Jul 2019 04:49:42 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id x1sm50673215pjo.4.2019.07.29.04.49.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 04:49:42 -0700 (PDT) From: Jia-Ju Bai To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH v2] usb: storage: sddr55: Fix a possible null-pointer dereference in sddr55_transport() Date: Mon, 29 Jul 2019 19:49:36 +0800 Message-Id: <20190729114936.6103-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 In sddr55_transport(), there is an if statement on line 836 to check whether info->lba_to_pba is NULL: if (info->lba_to_pba == NULL || ...) When info->lba_to_pba is NULL, it is used on line 948: pba = info->lba_to_pba[lba]; Thus, a possible null-pointer dereference may occur. To fix this bug, info->lba_to_pba is checked before being used. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- v2: * Avoid uninitialized access of pba. Thank Oliver for helpful advice. --- drivers/usb/storage/sddr55.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c index b8527c55335b..d23aff16091e 100644 --- a/drivers/usb/storage/sddr55.c +++ b/drivers/usb/storage/sddr55.c @@ -945,7 +945,7 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us) return USB_STOR_TRANSPORT_FAILED; } - pba = info->lba_to_pba[lba]; + pba = info->lba_to_pba ? info->lba_to_pba[lba] : 0; if (srb->cmnd[0] == WRITE_10) { usb_stor_dbg(us, "WRITE_10: write block %04X (LBA %04X) page %01X pages %d\n",