From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B9FC28C5B9 for ; Wed, 23 Apr 2025 17:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745429398; cv=none; b=dTA2bTN/TSwxZIXWdT33ixjevzYH0ijXDtNSZLghHeguKxWP2XSlD6z4x/sE9y7Sq4WE7IEhvdVTyRPuXdnNS6vTTBrfQYI1Kb2CVJA5idn5mv7WZeqBEBnJAJuK7KWQcgNynGxDVbRNhD85WEBa+ePdRok03H3YWPfrYNu4FVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745429398; c=relaxed/simple; bh=0PhYhQW3e9niKo2H334ixansrbnvf1A301EOSSFBo6U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hwGBwewHmL01Edc+BLuAfCHm0733F6i6gJOWVxxJzxL6E9nAFyOmNBYKv6uY2soYA/sDcBBd7P3FpePLcUs99oblKqTY0QJw16Mcqpy3hv5cWGdeXHolpP5dnJ4l0f05M7Q6LA10sJoehTteNZYQXZk36BWcPbqUkF3bsnlyKHM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=HL/jtx2c; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HL/jtx2c" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43cf628cb14so10266385e9.1 for ; Wed, 23 Apr 2025 10:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745429394; x=1746034194; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=oH2LFbAba/qda5PxRdibIeZbcQh5j5Nil5v6rguHVm8=; b=HL/jtx2cjZihqX5BOg4aSg79hqiANrp5ZWl2xMRv/RMpSXfMkY+tpQzSWO09XGbKm+ 3WRSm1kDssuM8sk13ag/TGfkSQ56AZswsu1qi/T4Y2AxIlqFqhvV+Y0Jj9lj84f3tqDx u1Yj1hZzx+/KdOrByUlU9TosArtzlTORqqvPHxdk9PVbeTOcQOlcCgtIfD8/+9zerZ2D I9gTT9kMwW0NYpdu5NytDGaQKObYRAj4CTQbVHPFCd/74l4JkAptLVUqUAweBFUjUvc9 DTw60MGjoaC9i9dgk4HYXE7z2T/niyz28B9gJuB9Hsxi2yKjS41bpbm3IllayS9nJTgG 06wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745429394; x=1746034194; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oH2LFbAba/qda5PxRdibIeZbcQh5j5Nil5v6rguHVm8=; b=vTYQmCJQ0ECauPj3XkuLH35NXlu7dKUvlCElNSZPk4KPHuWpTB+0M8UYefgatxOUYS YsIcuOnck0/rGjxr/cA7d9134ERJQYytTsf2sQTjPnbPeAIn5QCHvRr7ah5eVholzj3+ mS77PWcJC1oNYFIIZ1LdkT2U02FSAVrJYLpQU0EkBAtWreVglCDYqRRTF8H1r2biSVhf RanGQplxP2uKj9EziMVN86Ji1rXltWikA2kMZS13zBVcxXlZ6ysHKWy3mpA0fwa0wNp9 2qC/2x0wIwPAB8a5wutyV79EWKqiujO3bgL+NumZ5rWP1Jodr/FBsy/CW0JGCOD39zMc 4CQA== X-Forwarded-Encrypted: i=1; AJvYcCUQHONT+50WTC+jtVINwvEeXBhkNbE/BXfoedS7EPmgymIKwT3mwdHKGz/opsNrgNLvAQsq1gxyC4qwfxI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6XJecIq9YPpQkAuxFrwhn3/YWiQu0qnljRE6AJy1H7VhHy2SX ug6srtzaGT1UBpwwr5k5R2Q3957ClhBuh1gTw7G3fLvBfcoo6+4XuR5DvlWpcn22XTIndMBz844 J X-Gm-Gg: ASbGncvJkQbZInRdjYC+H25UgQzKBPdjYF5wMEhKsTxTRXriCKpurrZUryN/TSCvANU nz7Eo2e6FKBbh0hxoSD4vGQEzQSXquN7TF1ZKBwQ7JLBu7PE6mdpCShoJP99boxBi3OtMsE79gl CIKzZd+GsDUytEPQqJGgMsweGqE6xqGkyX6Q0ixHqw4Cqhuxrlph/rXA0qLTwYitEnbLMQ/e1pT gn23BlJjvecXZeia7doyinabsZx4LzDUR6+77L2hXpbgqhQFAot/j7VF17BQked+vuJqFXoqI9a ZW9FOa5V2ilcEeZigU7hKgU78vDMqYrsXsv4QFF0uAp8C/+BUTIJ1ilP X-Google-Smtp-Source: AGHT+IHrc3jKIu/dZDdMN5LGx7SYc5pxapEttECD3if6r0VvjDHa20st5SLgP98C6SszLOfYP04REA== X-Received: by 2002:a05:600c:cce:b0:43d:1bf6:15e1 with SMTP id 5b1f17b1804b1-4409aa605c0mr554375e9.1.1745429394577; Wed, 23 Apr 2025 10:29:54 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-44092dc229esm33348255e9.40.2025.04.23.10.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 10:29:54 -0700 (PDT) Date: Wed, 23 Apr 2025 20:29:51 +0300 From: Dan Carpenter To: Romain Gantois Cc: Tomi Valkeinen , Luca Ceresoli , Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH next] i2c: Fix end of loop test in i2c_atr_find_mapping_by_addr() Message-ID: References: <2427370.em1n7HOibB@fw-rgant> 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: <2427370.em1n7HOibB@fw-rgant> On Wed, Apr 23, 2025 at 05:25:44PM +0200, Romain Gantois wrote: > Hello Dan, > > On Wednesday, 23 April 2025 10:21:18 CEST Dan Carpenter wrote: > > When the list_for_each_entry_reverse() exits without hitting a break > > then the list cursor points to invalid memory. So this check for > > if (c2a->fixed) is checking bogus memory. Fix it by using a "found" > > variable to track if we found what we were looking for or not. > > IIUC the for loop ending condition in list_for_each_entry_reverse() is > "!list_entry_is_head(pos, head, member);", so even if the loop runs to > completion, the pointer should still be valid right? > head is &chan->alias_pairs. pos is an offset off the head. In this case, the offset is zero. So it's &chan->alias_pairs minus zero. So we exit the list with c2a = (void *)&chan->alias_pairs. If you look how struct i2c_atr_chan is declareted the next struct member after alias_pairs is: struct i2c_atr_alias_pool *alias_pool; So if (c2a->fixed) is poking around in the alias_pool pointer. It's not out of bounds but it's not valid either. regards, dan carpenter