Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6807113rdb; Tue, 2 Jan 2024 14:22:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKlqYfiouyTumnZN/kYd1QAKieTzaArPPX3bcNFvTzVVH+s/FmsgJmrpE5URWPKI1QkfxF X-Received: by 2002:ac2:548b:0:b0:50e:3e42:7422 with SMTP id t11-20020ac2548b000000b0050e3e427422mr7248199lfk.114.1704234149089; Tue, 02 Jan 2024 14:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704234149; cv=none; d=google.com; s=arc-20160816; b=Ghk/Kh5Vy1rBVPshcZSP9PGmbFHqL2cAS03VOHXxTwAPa1s9LWKamiR96sURLbdp4E MmRew/WG5a2rh534fZsZDtoJUYO1Us/+XM42Ke9rXCP50KHdOYAgZbq+NJk0mqKu5SWR rc6UsXoCqasZ1V5tu5PVT9JYAA2dTtxDqEI7h90BdBAeYl82qdEEXfbZBPCGXnVy+KZz TU1HYz9jYmWjmZka0UeeiyM0wzZTDwpnpPXiLjQPxTfJerLafHWFdFbhpBRIPB1zBiO1 CKrdPIu1iOkDjN3wl56hhjFAt9fBT05aEdJZNe9SK6D0HkwefNI7DEKoukee4Nv7sPll 61Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=e31awxvnUFU2mzL1bStxukrBXES4Vp8ekijyPrTWOWY=; fh=KqR1U1S9RNw3ysw6D0nU4Wl5Rpbz8gurvEZtOGXGcvQ=; b=rbbpXn0O/QDYpaoqaUmpuy2vyx4esRYTdqJTjjJDx+FNoRJ4mw05gho5vH2mE9ebgD Tlfd50/cU9F1F0YGuIeb47kLkmcn523VPPbILdVZG22K9aq8cit75m7HhZbBxWyKaBlo FqVbziE0aJnaryWMRFV7dJ6HYuyphz2/2H7srgXrlivk29lFotR+5EfbJpAq9v6ZVmDp pJM08f6KXkPA3kzQu52TqkACpuQDIzEJq8nEuqzT/rtfoVXlDKBMzGgpEQjaMAPGfq1u Z3yIUifXOPNv2k867RR1K69FAaBZSEFcMG5XSttXRl4tiJCsrFoQe4s5Lt+aasHRa3Ip BGUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rl0TtHe0; spf=pass (google.com: domain of linux-kernel+bounces-14934-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14934-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ch1-20020a0564021bc100b0055482b6364bsi9263109edb.179.2024.01.02.14.22.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:22:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14934-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rl0TtHe0; spf=pass (google.com: domain of linux-kernel+bounces-14934-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14934-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id CE51B1F236A3 for ; Tue, 2 Jan 2024 22:22:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1991417740; Tue, 2 Jan 2024 22:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rl0TtHe0" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 CD9ED171BA; Tue, 2 Jan 2024 22:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6d9ac5bd128so2475813b3a.0; Tue, 02 Jan 2024 14:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704234117; x=1704838917; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=e31awxvnUFU2mzL1bStxukrBXES4Vp8ekijyPrTWOWY=; b=Rl0TtHe06kkTcmVCV9mQKpAMeESgJL9FtPq5CzhQPgFQUvv1gbaU8uccg4OtMdR6mI VfRX7StpWxF8va5/2fPQh1LKFBgRsiR009J1uqf95uEhDghS4OZHk8bDqJKBJ2AISz5S 6GBR+wyVaoLAuGlf0QE8A3oKMt0rLS50Sxgiizt1wi60LhmNN2h93JD+HxNd5rWF35uN vEEwlGYizSBhkij8JvyenvfocdT8n4NQYq2pCVahPHSaEyO4/DZLOvhksXeMf8f2yTSz j0bTtKwxCLY7pFtP1AiQAfmT45Hb4+sXptRUC/gKjBv9HVYvRAWBmHlukyAL/Rd0674f PNVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704234117; x=1704838917; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e31awxvnUFU2mzL1bStxukrBXES4Vp8ekijyPrTWOWY=; b=nm4d+2s17uPDO1twkQpvmuL5TAPgOVj0tEb1DS6CRrzcUpOM7A/uxACYGQ5EwMr9rp l8kPs3A8erZLmIIjRrNTImu7VPnrSKL1wxy9e4rjtHvC7uB1QifP97+m7ML6myP7nSzh ukYdK5+CAdzrr1e4G5Y4dUIu055BPO2BQSe7VBDS/6J84Tp2/GoC4cr+lHgX8ObcAb/5 QqFQ3Ja+IFGZZdNoxFC4jsgygmrjF6t6p0PJfjKgyhdEPimjqG9I72puOW2/12S9pNFc bRMbnlqyKY9zbtWPsC72VA5g4SqL3ApZ/fMWitHGmO7vCRlVN0GMkxhGVW9hGTFWWlBU WvuQ== X-Gm-Message-State: AOJu0YzVhxxW1LYg89nsDXyU8dg62E8YMzl2D3m/JsjBmYxzWHZNZ+IB scrS37Za1jypXXFPWqDyasBvRt/IaI4zdg7TRJM96n3NnSJFMg== X-Received: by 2002:a05:6a20:f9f:b0:18f:97c:8263 with SMTP id ga31-20020a056a200f9f00b0018f097c8263mr6190446pzb.109.1704234117108; Tue, 02 Jan 2024 14:21:57 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1704157631-3814-1-git-send-email-zhouzhouyi@gmail.com> <20240102194209.39dac963@jic23-huawei> In-Reply-To: <20240102194209.39dac963@jic23-huawei> From: Zhouyi Zhou Date: Wed, 3 Jan 2024 06:21:46 +0800 Message-ID: Subject: Re: [PATCH v3] iio: magnetometer: rm3100: add boundary check for the value read from RM3100_REG_TMRC To: Jonathan Cameron Cc: songqiang1304521@gmail.com, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, "zhili.liu" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 3, 2024 at 3:42=E2=80=AFAM Jonathan Cameron = wrote: > > On Tue, 2 Jan 2024 09:07:11 +0800 > zhouzhouyi@gmail.com wrote: > > > From: "zhili.liu" > > > > Recently, we encounter kernel crash in function rm3100_common_probe > > caused by out of bound access of array rm3100_samp_rates (because of > > underlying hardware failures). Add boundary check to prevent out of > > bound access. > > > > Fixes: 121354b2eceb ("iio: magnetometer: Add driver support for PNI RM3= 100") > Fixes is a formal tag so needs to be part of the main tags block > (i.e. No blank line here!) > > I'll fix that whilst applying. Thank you for helping us modify the patch, I learned a lot during this process, thanks > > > > > Suggested-by: Zhouyi Zhou > > Signed-off-by: zhili.liu > > --- > > drivers/iio/magnetometer/rm3100-core.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magne= tometer/rm3100-core.c > > index 69938204456f..12c2e3b0aeb6 100644 > > --- a/drivers/iio/magnetometer/rm3100-core.c > > +++ b/drivers/iio/magnetometer/rm3100-core.c > > @@ -530,6 +530,7 @@ int rm3100_common_probe(struct device *dev, struct = regmap *regmap, int irq) > > struct rm3100_data *data; > > unsigned int tmp; > > int ret; > > + int samp_rate_index; > > > > indio_dev =3D devm_iio_device_alloc(dev, sizeof(*data)); > > if (!indio_dev) > > @@ -586,8 +587,14 @@ int rm3100_common_probe(struct device *dev, struct= regmap *regmap, int irq) > > ret =3D regmap_read(regmap, RM3100_REG_TMRC, &tmp); > > if (ret < 0) > > return ret; > > + > > + samp_rate_index =3D tmp - RM3100_TMRC_OFFSET; > > + if (samp_rate_index < 0 || samp_rate_index >=3D RM3100_SAMP_NUM)= { > > + dev_err(dev, "The value read from RM3100_REG_TMRC is inva= lid!\n"); > > + return -EINVAL; > > + } > > /* Initializing max wait time, which is double conversion time. *= / > > - data->conversion_time =3D rm3100_samp_rates[tmp - RM3100_TMRC_OFF= SET][2] > > + data->conversion_time =3D rm3100_samp_rates[samp_rate_index][2] > > * 2; > I've rewrapped this to be on one line whilst applying. Make sure to check= for > side effects like this when updating code. If we don't tidy it up at the= time > we end up with gradually worse formatting over a long period! Thank you for fixing that for us. > > Applied to the fixes-togreg branch of iio.git and marked for stable. I saw the commit on the fixes-togreg branch of iio.git, exciting! I learned a lot from it ;-) Thanks again Thanks, Zhouyi > > Thanks, > > Jonathan > > > > > /* Cycle count values may not be what we want. */ >