Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3298861ybi; Mon, 29 Jul 2019 04:16:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnCg5uGI0Lak2cJIZapbMr/ixeGo8I40+MVuh3N7HuDGDZTX/DS43/gXjbeIarDfph8Gja X-Received: by 2002:a17:902:b702:: with SMTP id d2mr113093763pls.259.1564399005223; Mon, 29 Jul 2019 04:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564399005; cv=none; d=google.com; s=arc-20160816; b=CjFyJkmwIVM09hR/nNwuv4EUJsJc6s+JtD3GzQgCs9QBT5lyOJCKxh2PqzEriVe2gm vWlSvGDZQd4c6PX6GgnvfW+d3OuwJMYjYrDh/vEDi1L2Onm3vuyiQv365COWTFTU21uj TxAxRJTesVbuIKceEsHb1GHVdXC1338Xaz/RMmG7h8QJSelLLQtjMUpk0g2ihyYfF3Yo J8cUann2eZr2tyzpSxgmwYPk1ghg0dOqr7XQWY5g9kzmfwca8Tazg0Mc4+s6nEtxX0wp wcvQp3Yry/R5sCaurEtMkC2ux4Kfhc+59wllh7neW2rpTE5B5EsGZYfhuu7VAyfB6RMW pu0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=5GrLNzc253B/Kp92PeukRRku/IaKJ9n8mYPDW7l69Jc=; b=JXz0KU8Hv/IYIFOaQyi9ig1Jit9sC/TIogn6LqWzwKc7pVA7puQaZQNn9bD8syVZQ2 vpSts5SmfWNyb+dSitmc/0Ek9Va3A08SE4+LVCdH4Nqu82WJiQgd9/RkNc9FidiPndJ8 x5fc3pEv6hrjpS4zpwcdExiYxrDF0Kb/PA7iPAgWeyDuNltzAXWLooPveJ7h29Wh4zDl z+lxx6jS4KEjg73XDJBsvIacbMuJC/hS9XNe/G5Jofzbn66sw9cMeL9AeZ7JEkCZ+j/M 2F8MlgMOUjBDB4AswWoJYQzK16X1AkKDIyoW7QrdnCOYiBJg733Ub1QkGz8cezEWKc16 G6vQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q25si24869349pgv.114.2019.07.29.04.16.30; Mon, 29 Jul 2019 04:16:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387641AbfG2LPb (ORCPT + 99 others); Mon, 29 Jul 2019 07:15:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:37792 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387575AbfG2LPb (ORCPT ); Mon, 29 Jul 2019 07:15:31 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A69DFAF0B; Mon, 29 Jul 2019 11:15:29 +0000 (UTC) Message-ID: <1564398922.25582.6.camel@suse.com> Subject: Re: [PATCH] usb: storage: sddr55: Fix a possible null-pointer dereference in sddr55_transport() From: Oliver Neukum To: Jia-Ju Bai , gregkh@linuxfoundation.org, stern@rowland.harvard.edu Cc: usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Date: Mon, 29 Jul 2019 13:15:22 +0200 In-Reply-To: <20190729100555.2081-1-baijiaju1990@gmail.com> References: <20190729100555.2081-1-baijiaju1990@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Montag, den 29.07.2019, 18:05 +0800 schrieb Jia-Ju Bai: Hi, > 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. Yes, in practice READ_CAPACITY will always be called and set up the correct translation table, but you can probably exploit this. > 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 > --- > drivers/usb/storage/sddr55.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c > index b8527c55335b..50afc39aa21d 100644 > --- a/drivers/usb/storage/sddr55.c > +++ b/drivers/usb/storage/sddr55.c > @@ -945,7 +945,8 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us) > return USB_STOR_TRANSPORT_FAILED; > } > > - pba = info->lba_to_pba[lba]; > + if (info->lba_to_pba) > + pba = info->lba_to_pba[lba]; If you use that fix, pba will be uninitialized when used. It should be something like: pba = info->lba_to_pba ? info->lba_to_pba[lba] : 0; Regards Oliver