Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp1017139lqp; Thu, 23 May 2024 06:58:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2VFjyFxGdjd8fB90RRonxyoA76Lw77C5YdT1u8kK9y8xEI0oz94LuRuSuxuJM2CFCrT4iFHC+NWH/aGbuMNO0LtU8Q+bNV8zZjnTtig== X-Google-Smtp-Source: AGHT+IHhZnH2RrPCS8rtJwnQ0ZWoH50/rDsiEjyujpkLoadv4S2WjbMIZACZWdMbGXFfuRrpPDCC X-Received: by 2002:a05:620a:1928:b0:790:9823:190b with SMTP id af79cd13be357-79499419663mr682819985a.16.1716472735588; Thu, 23 May 2024 06:58:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716472735; cv=pass; d=google.com; s=arc-20160816; b=XqLw70K0C3tEPa1uyNGN6XymfCo2VFw7+1RnUwx7UhxBINb5WRhYBTshsOaIL7GQnR qbSd+bGZ+TcpIJjkwWI+6UxwuHZPrQP/afb1IYKSngvtro1ct54+AN06CI5m6212kGs4 ik1y21oclWsTV+PD9EiHm4D40yPMVd93vcSUMU2/v3Ea9cqWTlK1i3p5UCu86FnTwVfg pvW0qUemu9dPnazkdnnYDjgBsLef2mQlNuAX/IzLnfi5TzpyGZoux7uTYTbZ0mxQTqA8 CIKCGU78DuISG+qfEuBzW0UJvjpa30mEoCWTdMNVARic4wCBD+rsQziKvuHCxozRaeOq usrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=+IVfzfVnpsjQwrwRDelvZB+uUX5J2/CLWWBqbxOZrXc=; fh=c0Oc7wSUMHapCIkD3ff/I1F1lRNZD+z7U3Hce7kK5Wc=; b=N9rrv+yF+qUfD0BdAUaSjPrH5F38U7o5tA0LbMxRfIfVuShdwkgrzMFQ9f9YIKfEwh n/Cb144VBSP2Of/B4mNqpoOxVOghonJq7vifTQyjIkwLGgIqA9C3/tbHZoo4WTgfPdlv 2HlY8Opfn2ePpSjAm2TruGNIL5Gt7IhHb/npK5VjlyGYbiU/bLNEdI5GT2zBSynnu3d6 /96wCjk4HPuleX9lwYPeoh4Jt6Iyoma1sTlQz79h34O0J1swLbsOFMpXSvvM0m4Bu8RX JVSuQ2U/hZp+aqhCxDrI2qI3e5RUJu/2wRsVSnxnnOIjUApl0cwbU83NDZTtlhXiwvLC R3WA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-187606-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf30abf2si681538085a.374.2024.05.23.06.58.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:58:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187606-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-187606-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 532011C20EDF for ; Thu, 23 May 2024 13:58:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A29614C599; Thu, 23 May 2024 13:58:25 +0000 (UTC) Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id F209714C584 for ; Thu, 23 May 2024 13:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.131.102.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716472704; cv=none; b=HNQEniKt/4ORxTCDDpktr72ELx68siu22gx7uszD5Vl6w7yR939jGFqdiL4fUevpu63Pcr3epfTrab3DvIDleIYgjERWYNlecajD94D6QhGtVXjME8ANt6nf4UDFIgSPqGoChagaWkYGN/PHFI8WGDSVnhQ2lFZxzULuxgMuWTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716472704; c=relaxed/simple; bh=ZxJY/vy8dQ5OzcdO9I/EsiKfnNp0n7gwTw3kEMSmU70=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MSwwekpbwctO7bLH+g1wmsHc33lv9rdrU0dX6F8ShGMV0ILgklb8Ceh/k3vhwKEj/Wc1FhFXV5evcBqYLVT5Zc1ewzq4Y0qd4rZNPH29iFKOhxC8oYtY/S/88o1x6m/x88QWZ4981xxK8u0yY3jaOYWCvw4PAHsllZ7P5h3QWbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu; spf=pass smtp.mailfrom=netrider.rowland.org; arc=none smtp.client-ip=192.131.102.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netrider.rowland.org Received: (qmail 538957 invoked by uid 1000); 23 May 2024 09:58:21 -0400 Date: Thu, 23 May 2024 09:58:21 -0400 From: Alan Stern To: Shichao Lai Cc: gregkh@linuxfoundation.org, oneukum@suse.com, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, xingwei lee , yue sun Subject: Re: [PATCHv2] Check whether divisor is non-zero before division Message-ID: References: <20240523092608.874986-1-shichaorai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240523092608.874986-1-shichaorai@gmail.com> On Thu, May 23, 2024 at 05:26:08PM +0800, Shichao Lai wrote: > Since uzonesize may be zero, so judgements for non-zero are nessesary in both place. > Previous check is moved out of loop, and one more check is added in alauda_write_lba. > > Reported-by: xingwei lee > Reported-by: yue sun > Signed-off-by: Shichao Lai > --- > drivers/usb/storage/alauda.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c > index 115f05a6201a..a6e60ef5cb0d 100644 > --- a/drivers/usb/storage/alauda.c > +++ b/drivers/usb/storage/alauda.c > @@ -818,6 +818,8 @@ static int alauda_write_lba(struct us_data *us, u16 lba, > unsigned int blocksize = MEDIA_INFO(us).blocksize; > unsigned int lba_offset = lba % uzonesize; > unsigned int new_pba_offset; > + if (!uzonesize) > + return USB_STOR_TRANSPORT_ERROR; > unsigned int zone = lba / uzonesize; > > alauda_ensure_map_for_zone(us, zone); > @@ -923,6 +925,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address, > unsigned int uzonesize = MEDIA_INFO(us).uzonesize; > struct scatterlist *sg; > int result; > + if (!uzonesize) > + return USB_STOR_TRANSPORT_ERROR; > > /* > * Since we only read in one block at a time, we have to create This is definitely NOT the right way to fix the bug! uzonesize is set once, when the device is probed, in alauda_init_media(). That is where the check belongs; if uzonesize is 0 then the function should print a warning and return USB_STOR_TRANSPORT_ERROR, because the device is unusable. It's probably a good idea to check pagesize, blocksize, and zonesize at the same time, even though none of them are used for any divisions. Alan Stern