Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp402587lqt; Thu, 6 Jun 2024 07:06:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/WmHsAno06Dzj0JDGWR6nf9uqFfb2W3rVoPPDWDTHGn7OLV8aK4CIII6+XL9hNit2ZNOVM7lAgceNpT5Gh4DuYqoY3Bvv4BDRed1SYA== X-Google-Smtp-Source: AGHT+IH/dVa5ZOHB29IUaHJYhbmLBmWDGvpwJNP9ozagsM5XgY545m/qc4IWg8PO4yW3135rmT5U X-Received: by 2002:a05:620a:2282:b0:792:bc86:2d21 with SMTP id af79cd13be357-79523fc2233mr563654385a.57.1717682773478; Thu, 06 Jun 2024 07:06:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717682773; cv=pass; d=google.com; s=arc-20160816; b=YHaE9NDzn0gYlnOUAPG6XRNv1c6sJWfiZER0ttOyqDZrcYnpatOE0/EBfWx+0a5toA coZ1j+Z34zFjxcpiE17q5fxc0aygutfss+NRTpUA+r8h+mnfDdjdeG8VptbOwkWWSB1q We1jFqJlaJWVJyIWqrOgTULCYGW6ziim31iDGvFMWUtKzEKP0kkePwiaBy2JK7+7kyGj Uwke8eWPhxg9iWCjKlHM1nRKmFsXnz2Vk7Wfe1qhp3t7iD42k6hs3uZP4t63FlWM1a5e 2Sw+SnBvdd3Chy6bR/H14qxGbKjNXjW07lXDKfqvrDUBralFDHNenaD19V1WN+A+G540 pq/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :sender:dkim-signature; bh=hkvtxfRBP8HwEJyE98iao7aEsT4W32s7jFfmrt+wfA0=; fh=ug6s2raG/oLn59GaOj50zXUfjlUOSI30gYEHfRJtWLQ=; b=KVSGrcmFUusYB/Pp+6ozH6XJfINSr0qZZPKWfWyQh4vzn+GwWtaPQeFoHgvixmuExu XSasM20HNeT1RfeAZOWe+cIDlnbu26PT1OoHG7Je77rHILOsro4D4TFlMSUQYZ6RjqxX 6ZnsoIEK9MlWnZudNwb2YMvnXoLe3gzm6ea/UTicmaNqGmcF/iDX/8Yjwbt1KB52ykzw vbn8T9KFfV3duW4oq2ydQG9JyCN35nH8/WtpD4bVxH5qcL9J0kffxQ30o9AKkk2HR7NQ N2vFOFDdQTXrTitQGJUgTYlE3pFNInQIQHX6jDTD1KxXuECnbkmWY/POxn7kA+PMg0Hs 8Bww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HGqJByk7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-204412-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204412-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038a869fesi16679531cf.173.2024.06.06.07.06.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 07:06:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204412-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HGqJByk7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-204412-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204412-linux.lists.archive=gmail.com@vger.kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 207AB1C243D9 for ; Thu, 6 Jun 2024 14:06:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37B4D1974EB; Thu, 6 Jun 2024 14:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HGqJByk7" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 CE9CF196C91; Thu, 6 Jun 2024 14:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717682729; cv=none; b=Y3nae9kMMljtHaDL8mDsVoWp18cX1gvBtkKvXboFSXDtlAlCmk8sf1nYJLvncCozKPBRiR3p6RLbW+uKpAEKBlez9pEPvjRNoGJeg1mWwpevoigGLf5evHVAjaIZuLCCzck7hYCZ1guJkf7RGMmV4COF8bxjfsLMK6/ippvUyRs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717682729; c=relaxed/simple; bh=i45Gu0FMOskw0DjvYyiQtFVhpvpJPcYFFKf1FYSoNCg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uiNJsSYyG9uNn6zPjp9PJ2rEo5SSgDLw1NoZYrNZOr8cvlbpkYl0Hw05N0krhwWoY52fx6ZEH37DgKlF5ygtXGt9vpx+nxBdSobbpcDZTnXozSW4byZgNmHAeafso68zTDCBwyuyo8iaLk2OQy7voKz45LyhDbVccwSMNgaqyWU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HGqJByk7; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f44b45d6abso9746595ad.0; Thu, 06 Jun 2024 07:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717682726; x=1718287526; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:from:to:cc:subject:date:message-id:reply-to; bh=hkvtxfRBP8HwEJyE98iao7aEsT4W32s7jFfmrt+wfA0=; b=HGqJByk7JbgtCNgLSqPFCWv5BXNsgjE+qssJT1/VQN0riMbhPkjgewVeUbBMIv6pZZ 9xjFd/T6jdEy4kGjIwl16eJ0prmUuVrQyos5e56JUipJxczLMlaAHGfc2/4R1cV2kC2V CO7vxxh0jXUdgAEXO2J/hlyKQPA5G/mkQ0Xclym+mQVEYm4ZsljwnNRWGRn0iivQ7Pwu OkQAALkP07iycdJb9zYKChumaSdkNDTUcwpsIlK3lfS+ybjJRlfDwL2nQv6QDq68HxLc Pi+loL2Y7C9MEk72/53qowLqJR6yIwKExp7TWxcTvL7s8mqNwyM4RT2Q54MwRdjG4s9x 9PTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717682726; x=1718287526; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hkvtxfRBP8HwEJyE98iao7aEsT4W32s7jFfmrt+wfA0=; b=Eq0EGtwqtA8PL2mXansZsIVKOW19VukCygvDMbg6wU1G1pOQ66LALU+mgICev/Hvg8 fcIsu9xPYdnJcygHbDiQVV5hXOsxKbZQwdHsgmve2so0EKemf9nK5RoMb8Pe0rW6+qSN 0gNNWIhIq6oSQSFLJ1HAvGTRTBaS2sIFiw0UkLFCqDOl8HhOc4rhXIr10Be0TNunNjVA H2lXaSoXc8RBzymttmyVCPcoHZ0dcORU0RIQ5pX05TornPQ8YB3D+wplmFHAlh1n/IGR zUlmnE8JFny2DF9+FGlSeQuOZuSH3HcE7I779NHA2p4YCWfgWT+iZXqYU4lhER1oS38y TFrQ== X-Forwarded-Encrypted: i=1; AJvYcCVaeNxSCIC7kTmMW6TUZ4gUkyOF4UTq9qniSBArj0nivNlJpqkHCOgNBQGzsWzIV2vi4DW6akUknXukzyKLuRj4iobfFz1J/OLs9m2RBr5pgIKB8HU8U2gXqY7+EGlN7URy3eRGgR6mqoUj7HaOjtezIfAzXkB9azD/K9cH/MkmfQoBS6Z5Q2439w8= X-Gm-Message-State: AOJu0YxG1oeFutDVKT0+/a8ZOszvUlrj6p0oNrPrddqMMVXo5TZ3nLn2 tRBgPBIchbvEfBwtGwJ2sqwcyhMRocGxBiV1nEoblmX0UAGi4bhx X-Received: by 2002:a17:902:e851:b0:1f6:7cc9:fb2c with SMTP id d9443c01a7336-1f6a5a6aec3mr63688685ad.49.1717682725317; Thu, 06 Jun 2024 07:05:25 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:329c:23ff:fee3:9d7c? ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd76ab8fsm15288175ad.73.2024.06.06.07.05.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Jun 2024 07:05:24 -0700 (PDT) Sender: Guenter Roeck Message-ID: <01c955d3-cec6-43bc-be7c-b6c1bde441d1@roeck-us.net> Date: Thu, 6 Jun 2024 07:05:22 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() To: Dan Carpenter , =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= , Jean Delvare , 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 References: <42331b70-bd3c-496c-8c79-3ec4faad40b8@moroto.mountain> Content-Language: en-US From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+hVL2Prf8xrX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CaG50OOm0hwPSk1J64R8O3HjSLdertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= In-Reply-To: <42331b70-bd3c-496c-8c79-3ec4faad40b8@moroto.mountain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/6/24 06:12, Dan Carpenter wrote: > 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 Reviewed-by: Guenter Roeck > --- > 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); > }