Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp367438lqt; Thu, 6 Jun 2024 06:13:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8JMD7kD3dpSSFrXgTucCi2CvkftHT8/ScRSxAsbeQ7yd15FIGwMOFIkRKoOpPptle2zjrVKowy2wh9k1xlkcmxo8VUpiJPNC5vkE3Yw== X-Google-Smtp-Source: AGHT+IFStgVXeVflD+mlTSxMUf3GGfeZ5MfXUYHLCQrpe5gZ+BaEyGlQGqRRpRU0MhRtzNoi4hG4 X-Received: by 2002:a50:d7c1:0:b0:57c:4882:3e3f with SMTP id 4fb4d7f45d1cf-57c48823eb4mr344531a12.27.1717679602216; Thu, 06 Jun 2024 06:13:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717679602; cv=pass; d=google.com; s=arc-20160816; b=HidGr60wilWbYiQ5gYBE+YPN4psEQamuKOrBkXe4EW18xYvUxnn5lwjySij7XwVso0 j8sP00Fz1kuUiVb3UxqwF/fN6ISmclB3mthIDrqUgOTgAPKIhZu37nT2L0RVKpp+aWbD 1ENJoj9g1G7pwnISugRIoPbHBL/+0mSe+nDINWrMBA9VDDxsni21OKUrHji/ch7m6ca3 n/S9UZvwwMoyMAZBnGDUdQKQYd8gVP4nbro7WAyRwNNyogBsfbKWBqgenCChnlRmmE4a v4KRJuHS1AKt1RtTbhaekkXoqt4ywkb5uA5fgCmNrSYixYfNw22XFAvmzUq/DxT/A4gP jDpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=PxE7l690bffTKUzQL4YoKYab1ziPbqqN+8E58otRGxA=; fh=QzNKNvCWjoOYgWSoqLENIm+3+J8d0q6DluqU6WJyir8=; b=aISmEVwYzxTogh72zwvc/MrVPZ2l8J1STC1iXLT+QopLs1yMu6E/xgS7XsfQW6X8vF STbuWk0eEL4XOfIGM3VKyFPDvg/tiZV+RQxV9+iQP4DDl4Ke/eT3sYnkXHZ4cGa9qBfE 0EpHDL48lYvNX7ytTtnxKw4a0TFy20NrM0FfwT4ZLS7dHubOeFFm+rz5abdX6tePnHDq WRglub7WXMTmrB3BjHCO00iMbH/RDVOea3BoDeb5ckWj++9oc9nGt7Qs/8xUv0QI6mTb iDpbAYLMbv9mstchTx51D4evT5AT2xYhvH1ef7MX3459PNX+fLBeGC5ytPaQAXbmCsm1 ZgNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fgWk78SX; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-204329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae0c5da7si669381a12.15.2024.06.06.06.13.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 06:13:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fgWk78SX; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-204329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 556411F26A33 for ; Thu, 6 Jun 2024 13:13:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED601195FCC; Thu, 6 Jun 2024 13:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fgWk78SX" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 94F22195FC1 for ; Thu, 6 Jun 2024 13:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717679539; cv=none; b=W1oo8JdllFnYj7RUX0vwIs1qvJUPFdIyLO7LE4rkZ3PeSdRXVkUfynAFqb3EqB3n6K+fnjZ8fTAlQna7pLseR1d6l8WSjTgWY9BBPJKCMBGCjt/xaHuzwOrQTeXX7m7NFCEOLrNgJx+Qif1t3fcUhlk3pLOjXBfC+80Ed9a2994= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717679539; c=relaxed/simple; bh=me6Ty41cRCSnMOmdHM0XNnCYCzQRzAGcL0KUR6aAOg0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=mNTOXHtq6bIg/1/Dd/8kMLzHpNTfRe+l+WECbfElPvwn+LluRmDfnODRbhO282rg2zai+z8cT+JYfYau8EYiU8E1UaiWoG42G6sumlrJJuBo1TBAWxnuIB4UfLaPIR4o7iUIjfSSfQ+HpKT4d7tDlKbw7dSKvSlIfUCDFP2YuQo= 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=fgWk78SX; arc=none smtp.client-ip=209.85.218.50 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 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so116996766b.2 for ; Thu, 06 Jun 2024 06:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717679536; x=1718284336; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=PxE7l690bffTKUzQL4YoKYab1ziPbqqN+8E58otRGxA=; b=fgWk78SX8ddpC3EEREr42d64HI1y7nQ22Omr+c54YWBSAgm1ki4ftHxPuX/dFbrmax Vydb4RhUhLaI/5Qo1SU3NBCD40CpR2mab47hE4T6g/HAkZrTdg4pH5TO+SXWJygrmtGE 1RTev4hbteS8gej3t/w6KljVdQRL/mslxzIGxYYdu9Zl3NKjlXPA7CZfrpDp7zse0pJp U2iuwZ7DG/+/aDsgKANoRzmVD0ds0xAXjqJFTrBcN1Hv6LaWP5kzlVLDsTMlawHrZtL1 pn7LHVIjUj5gXUJN0mKs2A7hjbd/UnuUobLRcscDga1WQoJIrYYu/sOPCoh/vR9qJYuc zICQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717679536; x=1718284336; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PxE7l690bffTKUzQL4YoKYab1ziPbqqN+8E58otRGxA=; b=AXtduM41ZOrTJoCNWGiYmA7DrFomsg/kR93BBK7QM7ujO+HICdlmaeOBUowBSPKUjJ VOJoP7AJMI48wYFFOYJmSlDzacoIX7sFb0gMqSsOHTWBXT/rmFSRoINRUN8o554BpRnp uP39btM+gBHmVU0ogLmlJtM30U8765lXIHjU5eGREnq6xfFPdwYbL6gknSRxqCNk4/G0 jjpfvUwYX8JDP9EFd0JIFqALPMtc20TWrahOz3FxECMar5QOgNjQL0HbQdeEEPna5Z5s HLV4lW8bAYz+Vj7hiUOhPUGiHy9UOf65X7zXGy7qlzLSFdrCJiRUMvv8zmBHmdZxd+Fb q90Q== X-Forwarded-Encrypted: i=1; AJvYcCWB8SYhWRFw0+7TEmNXUD8aVOz1FxgwWcdjXlQEiuOS21QgjcpxG06q0QadjiopkHqxiIbOu+GSS6CJjvjlqinTmZSqGcSlMwG5b8V3 X-Gm-Message-State: AOJu0YziGzsNyDfftyRMrRlk0nUkPitx0k1pWPQ8A6FdNmji4xEBVsfK wK/AHH+TGj1bXNaLHkF7GdgwQm+TRmm/VINj77muw+VuHpYhi7+V/mrKTuipAgk= X-Received: by 2002:a17:906:390f:b0:a62:5ff6:c728 with SMTP id a640c23a62f3a-a69a025318amr374676066b.76.1717679535821; Thu, 06 Jun 2024 06:12:15 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6c805ccb1csm96890166b.80.2024.06.06.06.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 06:12:15 -0700 (PDT) Date: Thu, 6 Jun 2024 16:12:11 +0300 From: Dan Carpenter To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Thomas =?iso-8859-1?Q?Wei=DFschuh?= , Jean Delvare , Guenter Roeck , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() Message-ID: <42331b70-bd3c-496c-8c79-3ec4faad40b8@moroto.mountain> 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 X-Mailer: git-send-email haha only kidding The "resp.sensor_name" comes from cros_ec_cmd() and it hasn't necessarily been NUL terminated. We had not intended to read past "sensor_name_size" bytes, however, there is a width vs precision bug in the format string. The format needs to be precision '%.*s' instead of width '%*s'. Precision prevents an out of bounds read, but width is a no-op. Fixes: bc3e45258096 ("hwmon: add ChromeOS EC driver") Signed-off-by: Dan Carpenter --- drivers/hwmon/cros_ec_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c index 41f268fa8260..b3ba7247e06b 100644 --- a/drivers/hwmon/cros_ec_hwmon.c +++ b/drivers/hwmon/cros_ec_hwmon.c @@ -212,7 +212,7 @@ static void cros_ec_hwmon_probe_temp_sensors(struct device *dev, struct cros_ec_ continue; sensor_name_size = strnlen(resp.sensor_name, sizeof(resp.sensor_name)); - priv->temp_sensor_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%*s", + priv->temp_sensor_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%.*s", (int)sensor_name_size, resp.sensor_name); } -- 2.43.0