Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp1034578lqp; Thu, 23 May 2024 07:19:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWNZRKnL4C3Md9MOR81vBmaE5aSyqqOYu8Qlhp/Dfaxvzd4zAR75Bgz/yifmuUvECU3whrqBiB8VWoe8V/BSv3EV/O8CSSLMW/hf/DnbA== X-Google-Smtp-Source: AGHT+IFdKN1CbZzcm0GOfPF2Czxf22tXK3mheNW8YwddqLo5Q1iw/G9AEQ2XapH1BQHssT/RAdOE X-Received: by 2002:a17:90a:ce92:b0:2bd:db8b:ca78 with SMTP id 98e67ed59e1d1-2bddb8bcb4amr2634113a91.33.1716473974682; Thu, 23 May 2024 07:19:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716473974; cv=pass; d=google.com; s=arc-20160816; b=oFMx5m4CstQkStqSuyEjdBP8fwN2ZDqjCzvSo9t+RecgiQ7qq3WovtwTF+83RIDEvm r6w1miBVAAg6OG7lECR5Dv7jkTlyikj04Ztvyj24R1oL0AxIUzw4rjsHgtTo7K8X3i7Z g/488FjcYAomOJodQi3BE24S/SrcAxlC0liCPbB1UFVE29cO673V5S4M3fzNo/x87TBt j5y0uPgWKe18hk/5Ek1R8SJAIxC6D7Jdsb4NasU6JpKcNkc9oH9nit9oesGlfoOLBB8a GLiD7niffCsmd0FxzXjRjeEE+ruoZRMIInhif2YazQ+78h1E3vQ+vbSoTsWY1oiWrqB8 u3xg== 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=9BFfIJ887Xu7iupAyjQklTyzhf5wXFP357/0wDTwzv4=; fh=c0Oc7wSUMHapCIkD3ff/I1F1lRNZD+z7U3Hce7kK5Wc=; b=aU8CMgf6qMBJlHOryN4Z1FlGHSekK+K6CpzvvwR/51JnAlLfGZjZ6VROH0zbBWdlYD O9Gw2kzC0+7qzXaixmRU7Qp49RqmSb3igLMO8CFH/398W5DR7hzNrmN0SmgNzTZrBSpa oWvKdJ0rVnog9iXcakkKAHsKf1PeQsa3m5j1U6wER0EPOsNqIditEF4k+zXvO99HeHuY TNx8p4BYkKhYC2dOZIM9kEQNcDz2z2506AtXn9+84+T7zXaQgbbz1jqKw65+E1QieiCi 8xGKXxkq+KIqik/2JtZhsFTq4+8YQ9jxDD70yS3uS5bjKn9rxCDN9P9Y9W7TbQwOVMBo DUzg==; 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-187624-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187624-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bdd9f45740si1716690a91.162.2024.05.23.07.19.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:19:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187624-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-187624-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187624-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C57B8B22F3C for ; Thu, 23 May 2024 14:15:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C65114B94F; Thu, 23 May 2024 14:15:20 +0000 (UTC) Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id D846D14AD36 for ; Thu, 23 May 2024 14:15:17 +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=1716473719; cv=none; b=ThGqknLyErSfNJEJE5+qsnquSmkxFXkHoy35JNG5aD/Lz9ua2BOAnBkIELZql0fBfweQ2pkr2WLfHa+vmlI7bCFhqxHPN11UbsHjy4in3DqU9l9FPhWJdg3furAqT8Qq8MxxH5Iaz4mVUHKk+hm6s6VFTdwYslDJOpmeBoCu3+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716473719; c=relaxed/simple; bh=5IUf0+zG4fFL42YLfBx8BZeqPX1R//xyjwcl6cKW7dI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yeb+9BkK9+AkJGS4snkARQyNh7PvGM/MhNWWx0Ob+Qs/fzc5Rdr2wbdxA21C2XGNNXQqg01EB4tuN0n/zeRVwTOwEnxbvoGm0H20+dz8QCa+V+tcVURFBlQcSdSCKmdB4W96YIopa0c77axZiG8DyzjT9mOcwDXiV/aZ2v5a0wE= 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 539510 invoked by uid 1000); 23 May 2024 10:15:17 -0400 Date: Thu, 23 May 2024 10:15:17 -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: On Thu, May 23, 2024 at 09:58:21AM -0400, Alan Stern wrote: > 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. Wait a minute. I just went through the code more carefully. It should not be possible for uzonesize to be 0, because it is defined by: MEDIA_INFO(us).uzonesize = ((1 << media_info->zoneshift) / 128) * 125; where media_info->zoneshift is always a value between 8 and 12. So the whole idea behind this patch is misguided. The real problem is to find out why uzonesize ended up being 0. (And it's not necessary to check pagesize, blocksize, or zonesize, because none of them can ever be 0 either.) Alan Stern