Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3325273ybi; Mon, 29 Jul 2019 04:45:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWEEvi1QBvffbgPkYNSbvxmnfzO7VVlOw88NOmzGYkPjOQCKdrwWXnbeCODCgNtk9NErfL X-Received: by 2002:a65:680b:: with SMTP id l11mr9141966pgt.35.1564400718337; Mon, 29 Jul 2019 04:45:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564400718; cv=none; d=google.com; s=arc-20160816; b=yxdfWymcHKhwYaBouPoXhMk/zQOYSYBbeOnDA5iBJRmYl12mF07duJ0+fcV0IUFogj m4R17vRF774f8aiFil24OPoJdU9ok/6uasmIIw6ysr7nNpdRLu5qABOgY6aS1bNyfn6Z KSFE83TAVRAZcFGA/UX9AYnRRhbvcp36fuuyRvSruGQXsUzekd641ZokAM2+6/Lr9V7D 5vn+sLrAU4qGln4CAdDaI3bLj+7nPbrFtTdGMCf3AOVN0aqn05G5wouOO6afWCvBgkLB wduINqr4hYtCE1VZemYKmAMalVNPLZ/8JMMimULp37oGwDRLMFwys3Y7ObhGdP/M6yAg gPbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=/GdbQmHDgRxOIS9Wz7Qs+ZEMMYW4qyH6JYf9o6A1T0U=; b=xzBlBRj1kTUKmJkRWkYfi4AaXIJipSQRtAFyF36lZpDRkjdptrRRgZUXuThv5xz13Q pTJ2ME1zBmEBv3rrGFz9gQIzAlXkhPuBwMO1qYWPJnj/1IaWCcFuVHPNW72jugqK30Sv TDrGeTWRPv8PxALzJ+v8I4PedsutPn6TU5Zt83YV4DIinoPhMvcZjggdRo8m7UrUU9dk 4hQ7VJspe5WCQAe8KC116SfSjtUbWjhloEkFXdW+EC8bpwj0ohfKEuAd9TzwmXmuk55s rGRDySySR/sRXkZ1aCZoKNeXq6+AbDRuaVuEOLZzCW5xGZOT+xBm7Lw98XZW4Zn3haVI ngXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OarXZMdj; 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 c23si26015710pfo.168.2019.07.29.04.45.03; Mon, 29 Jul 2019 04:45:18 -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=OarXZMdj; 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 S2387783AbfG2LoK (ORCPT + 99 others); Mon, 29 Jul 2019 07:44:10 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43611 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387701AbfG2LoK (ORCPT ); Mon, 29 Jul 2019 07:44:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id i189so27905981pfg.10; Mon, 29 Jul 2019 04:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=/GdbQmHDgRxOIS9Wz7Qs+ZEMMYW4qyH6JYf9o6A1T0U=; b=OarXZMdjsEIRH/B2hQgEb/RKA3uNUmUrj/k5djGinq6oLebsIYvUwa6wNSoYX6RAfW QeeSa4wZ6xZDk0h9GfP6/ya67iYrpV+8SZ05T0c5+RPVhigzCm6CW6hlwn99gdAGb15V 0RkEqZudL0Pmw4ZFHjoxenhULkWdsfZyYIa86MmfPsPETKlD5khr0WnI4zV3712tWpMm JI7s34YoD2VACRzirHt0oQrfaAB4j5HnAyeHpQZapbzsLizkjFStVHmaq2zD6vpTMqaJ B+WZX8inoo3mTfh/IERGkPm7npXdbNp/r6f7IX3NpHVRqP6DPD7uqFt0mx2OsipuUzW2 /IFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=/GdbQmHDgRxOIS9Wz7Qs+ZEMMYW4qyH6JYf9o6A1T0U=; b=mvlstNHGWpPWmNrITbHSCx/GglpXY7J3WQAbXpsz/qr7eJ4KtKij0c8jqfEY9Si8eT ABxrOZTEELGLRKOZwv5cRaeAwUBKvHzTws5CwKQZF+KcCslNZh3zZVudWHJaXXby2sU6 d+EPgFtNmsla6P+RbuoKKYwNEGHBs1kA3t7lVPnBgV2EEyVE6a36+ZNjGbWZ5NvTRdJp yZzm05ECiq1kYNBuR+KQs0EVhTKNy1Uw/MaufGz1NjrK/64q5iBf+h9iv9j0en9ypY+M T0T9P7Ct16V7Wf0jDe7dS2wCSxfXUiDugwV9t8+Updp8hL0z1bdvZa+BhELtvn34SPII eoPg== X-Gm-Message-State: APjAAAUIVYMl9U2IRvajEQ2uME+7oT5Qk40H++FPgN4ePxqNGzmUgoq9 vKoRIeen24NhYBYPCK3OSOHrcuhoysw= X-Received: by 2002:a17:90a:cb01:: with SMTP id z1mr110535882pjt.93.1564400649494; Mon, 29 Jul 2019 04:44:09 -0700 (PDT) Received: from ?IPv6:2402:f000:4:72:808::177e? ([2402:f000:4:72:808::177e]) by smtp.gmail.com with ESMTPSA id z12sm42867392pfn.29.2019.07.29.04.44.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 04:44:08 -0700 (PDT) Subject: Re: [PATCH] usb: storage: sddr55: Fix a possible null-pointer dereference in sddr55_transport() To: Oliver Neukum , 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 References: <20190729100555.2081-1-baijiaju1990@gmail.com> <1564398922.25582.6.camel@suse.com> From: Jia-Ju Bai Message-ID: <8d21d256-8c03-7864-d45b-fb7f2590721e@gmail.com> Date: Mon, 29 Jul 2019 19:44:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <1564398922.25582.6.camel@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/29 19:15, Oliver Neukum wrote: > 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; Thanks for the advice. I will send a v2 patch. Best wishes, Jia-Ju Bai