Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5567590rdb; Sun, 31 Dec 2023 06:57:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLmyGgFXkRoIvXGcUy2d+0AbthkQNNkzEAOC5sip+ppV8R5nbkUmCSoalEsYHd23RyeEun X-Received: by 2002:a17:903:2341:b0:1d4:bac0:5056 with SMTP id c1-20020a170903234100b001d4bac05056mr38240plh.119.1704034645549; Sun, 31 Dec 2023 06:57:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704034645; cv=none; d=google.com; s=arc-20160816; b=z1IeFyiu4ytDhHcyq2aNPRKVGv3TgD2Ma7HE4LJMrtMo5dvn3xgrPqdC3fJrzPekK6 J8zdj/lJ6ny4apFKVMDq53CTv/tx667t/rozsI/Ci+TxlEGh85vklPod4nLwPZ4CcvDL ZfWbBPx8JC2uojmjPhI4YhVmqwU9+PRr/xGpQxo4ZSQtm6gxHTHpP2j/gmCSfHjSYsR9 X0nMDmj0t9xUi5CEh3vi5sDWaaWKlekM6GXPxBdJMRWkfzpq4x/1D7WuzpdRyQTcptbe cMci0ag8XhBvp7qDarFu469ROP9IHNHdFRKfmNoMxJxIp/rTBjY4vgD9FTnJZonmXez8 nLrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=fTz5TyGFzp4ZGQ+lOKRvj2KlDWSDsjrIEBja4htkNhg=; fh=8oQed1a9TPaHshR1MtBmE8C3AW1jdI5MFAMZKcAqSr0=; b=SwG3Miy10LNGkCwkWEiq2m2/WDY+6teviFamBmKcFg7h3kVZsIcObI1/ngEK4GYgNC Uaxp/KCnFHUCIAxYSpCsvYrkvC3Cc7vIm9xw+0aq0YjuNa2rGXNpr2qHsDEXE66Lr/1Y rU9sc5gm/sE21Rde/hhkiCo+Mr7OjsPVSYsYjH8PNZNi3NPF+t8k3nxtUTE1TSBEAvVn Rc+6X8XkUz2y9xtg5feFsM5Hog4Kx+Cme1odZQXzFcmvBHlI2rCLhAhmScWP6Yk3n57j a8UrE8d98jr5d2mPRy1u+myTImw3ZjWoMMe3VSo+ODCjLWn6x992ydZS7SlFC5q65RI7 t4MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Gh57j8zY; spf=pass (google.com: domain of linux-kernel+bounces-13722-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13722-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m1-20020a1709026bc100b001d466549dfbsi10087890plt.563.2023.12.31.06.57.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 06:57:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13722-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Gh57j8zY; spf=pass (google.com: domain of linux-kernel+bounces-13722-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13722-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6DF99B21090 for ; Sun, 31 Dec 2023 14:57:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B3B16126; Sun, 31 Dec 2023 14:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gh57j8zY" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 431C16112; Sun, 31 Dec 2023 14:57:08 +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-pl1-f181.google.com with SMTP id d9443c01a7336-1d4b650bc9cso1947895ad.0; Sun, 31 Dec 2023 06:57:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704034627; x=1704639427; darn=vger.kernel.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fTz5TyGFzp4ZGQ+lOKRvj2KlDWSDsjrIEBja4htkNhg=; b=Gh57j8zYkzIVg9urYyNHY19j5wXzZwnsOSOtGaLC0ZgO7qlOha5voIr2xvUND6UoYa g7pAdSeBsvd346NmJi2KQ6O9WhY5kUFshiF+U7Qf6eLgtCRP6UEQ3o6jmO+lNeJxXT8x SDPMgAlgG18cSC/f7Zodm3ajSOv3QJUiOb3OdFbr1pbNKClHamUEF8aeUD4IulFs6yr7 fNPE8pz+vrLIU7Yqg2g23ByoOTHnf0OKe/1GzdNTTYcreojySldf2ITd2Ars0QunOuDo ivqtPM8cJMAvv08MHnLQwB56zPcRibwlrM4Gvmo1n4ygxw+tGRP3KmTltUAv5Qyio58a DNXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704034627; x=1704639427; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fTz5TyGFzp4ZGQ+lOKRvj2KlDWSDsjrIEBja4htkNhg=; b=AKOrek7jSkze6zUlyhhpNzaHQlRmonX41PpQ0X04EyVLadFHQKR9tPaOg/kE9Cvi9s Ch2CY3oKJtVbYNfBhPy6I9TkvR9oOmkqO4Z1USDMCswS+cphtGcix3otiWrqXw+hXanQ rEGr1mjWVjgRArLgr6VqJ53ezQBQyrbJOzLRqy9KJHmuAaotDDmlxzge4S/bsDXN/yeA vt7ba8XbRi4vMHAc9tYghpmZEJXLOGylx+dNJP5K9z47uAUvhWb+HJHkDtc5LEuSd8j+ mrujo3rW/m8WHH9Zw8fcOrrVLx/h9+vuQlgLv3xHyZ/ySCwnCBYxlh3RMNRLufBQnez9 n3cQ== X-Gm-Message-State: AOJu0Yy+h4CzOB5mL3fe1u8GrCXXsimKf7jWn3j8cPyg5pXcpw0XESiS Q5ABPV7R8q7FrX9Rcg9mXz+5txIdaZPOrw== X-Received: by 2002:a17:903:244d:b0:1d4:b017:a053 with SMTP id l13-20020a170903244d00b001d4b017a053mr2183914pls.116.1704034627330; Sun, 31 Dec 2023 06:57:07 -0800 (PST) Received: from localhost.localdomain ([154.220.3.115]) by smtp.gmail.com with ESMTPSA id r4-20020a170902ea4400b001d3f285157dsm18704367plg.124.2023.12.31.06.57.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Dec 2023 06:57:06 -0800 (PST) From: zhouzhouyi@gmail.com To: songqiang1304521@gmail.com, jic23@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "zhili.liu" Subject: [PATCH v2] iio: magnetometer: rm3100: add boundary check for the value read from RM3100_REG_TMRC Date: Sun, 31 Dec 2023 22:56:44 +0800 Message-Id: <1704034604-9846-1-git-send-email-zhouzhouyi@gmail.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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. Suggested-by: Zhouyi Zhou Signed-off-by: zhili.liu --- The format of the previous patch was a bit problematic, we are sending it again. Sorry for the trouble. Thank you very much. -- drivers/iio/magnetometer/rm3100-core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c index 69938204456f..fc50b6d4a334 100644 --- a/drivers/iio/magnetometer/rm3100-core.c +++ b/drivers/iio/magnetometer/rm3100-core.c @@ -586,6 +586,12 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq) ret = regmap_read(regmap, RM3100_REG_TMRC, &tmp); if (ret < 0) return ret; + + if (tmp < RM3100_SAMP_NUM || tmp - RM3100_TMRC_OFFSET >= RM3100_SAMP_NUM) { + dev_err(dev, "The value read from RM3100_REG_TMRC is invalid!\n"); + return -EINVAL; + } + /* Initializing max wait time, which is double conversion time. */ data->conversion_time = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][2] * 2; -- 2.25.1