From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 4427B2D5C7A for ; Fri, 10 Jul 2026 15:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783696876; cv=none; b=XxmTFQUxk1RrYpz/SgToZoGj9ZBd1NuJg1E1P9RDsEc3jk8V7VgmIr2XsLxfHsLrmTaqT264MmYyrlJNyz/NqzxL7IXJUrhJrpfXjKRKU0GNNOaUpdfjr8TG9hGw4B546Go7vFAJilnelep5v9lnA3McsPxlKuOksb0tJ4Q/lfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783696876; c=relaxed/simple; bh=SqJcUT73x7eoB0S5h/3ctXw/oHOCbm6jUb+xoKd9M6I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=b5jgK5Usa3FnZqrRwaClB/u1u0dvR1wOi8PZU+yCyPsHi4xzcuZ0GWrJ6RCxzffJ34lL5qZazHka/KW497Y9t2R4rUgkr7nupUz18En7mgoti3ezix7+Azo8nq8usyxXbHwoQDAqxz7JW8x3b0aIm1bS4rhN7lWoAKgadaJUVAs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b=lJw+CmBZ; arc=none smtp.client-ip=209.85.128.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b="lJw+CmBZ" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-80c5cb9a888so12245357b3.3 for ; Fri, 10 Jul 2026 08:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1783696873; x=1784301673; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5W0IIRCYefamj/FFcBfXSVL6e8CmPqSzJFbWhXGilG0=; b=lJw+CmBZ9FEP4GL6shV82q3d99qFztcwUAo2haH90jFQwAq59YWNOUuWuW5h7DlV3Q mvyNRRZevHvyWNX7mfl7fIJ1+SVRZllPyY+yq/rLeFk0xzSiFHodV8jS3t+bUxDNNaHA q9i7pCs0Q0ACKCR684kue7mKQUYkBAk1ydVpuCAuwu7tbuFsCqVCjGt1LAQX52yC6AKq f6D5xdIPitr6Tos9dGYmykfDEGRtp2svX/bIiMKc3BRDpB+6UvJjCpuG9L/C8ubqduQV ZT3DARzw2I2KbBnH9ObLQlshfYQh+oQvc0zVtejG+/5VZ8h9XvbryzMCajVdq0brfuN+ 5l0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783696873; x=1784301673; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5W0IIRCYefamj/FFcBfXSVL6e8CmPqSzJFbWhXGilG0=; b=ZvDlsVh/mQFq2T+u3aCxbGUxCZ5KYwFTd9YEhllxC6FRmubiZt38FDrlrOlPj7t7JS 27f8+XP4B2tQBphCbofDPQNSJ6D+DfVijYxSuDHIHimaQe7iGpvt+mVex4AukoscLtkp YeUC4qiiKG5tnFVYYOdjIFTqHjsasVsDGKE5EcUnkyQrh6ME1UGf4kFGn/Hbt0bw7q8P g78+HUQ3iq2cJYYMtFvCWhQspcxGFMkAsAhc1CK32qmo79aL8r3XmTnkaBJFA6xris4P bQ/Qvx5/YQfQdn5pHZGbyaGrYa76iX+T29SvWbLMIqnWoXtiB+vSMHRCjCR3qyWUdL2I XluQ== X-Forwarded-Encrypted: i=1; AHgh+RqORPdwt5G5mW64ZtEQ2aKecbol3KVrPWggY4Z9Fm9J/YYK7kQv1xJZXyh31tTUAAZqJUS0JrRTKe5QUEo=@vger.kernel.org X-Gm-Message-State: AOJu0YxhEPvOnDCDqvN7HDz5InFeAEcrGphwH9chqTJBB26lZ0Dwt7yA OkzaBmOEswIv+HzZ3eQJjaFB858KeeS9BCdgnXoFHNVH8alzVAc8IP/FdXr43YC05mY= X-Gm-Gg: AfdE7cmKeGCZzjj6eFqMe9FSy5abwWW0FFno6rq74zyBs5LyxYHROBB/TOa6yjtO6K6 Xp7HQcHQhg4UWFLiPjhkfxYQ+1/iU71HxL+LsonH6w8xf7rN7Sikl/9e3fAk5G82YAc5SZGMib+ vMaThvEF+NaeTfwozci4FEiExhRZeZzo1s4vFsBkrVyIZBWawhINFRvpcIoPjL7OVS5USsB1Qlp GCDhe0bmxIhnkIQZLUIz34G0w+zEVwhZZ+KgbPuC7fezR5YqB9UzrdlWaICHWCy3ohrw4AJFOPF h66WWdUeqkD/Nnw5c033fLRGOmt6q9dJBgncar5l/U0DKmYvIAWa4QDmkiDAnzz2C8WsTFEVt4s lRaDVTZNoWcPWv+/0cPD1oE6/KuuiXkcszJmem9LIT/b+r1Hm1/IRQ7YTone+JyBSg5fd95G8d0 3n/NY9FpXJWwPaFIaHXt/YtA82Y7PGj4t8r++jN0bvUnbNAWDl/oWv1xtePnKX X-Received: by 2002:a05:690c:e3f2:b0:81e:79f0:48b8 with SMTP id 00721157ae682-81e79f04e78mr35781247b3.7.1783696873086; Fri, 10 Jul 2026 08:21:13 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:500:1b03:95c:fbd4:4d00? ([2600:8803:e7e4:500:1b03:95c:fbd4:4d00]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81e6be9834dsm48620217b3.9.2026.07.10.08.21.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jul 2026 08:21:12 -0700 (PDT) Message-ID: <9845b343-8138-4858-93a2-df8e01c7d64f@baylibre.com> Date: Fri, 10 Jul 2026 10:21:11 -0500 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] iio: proximity: hx9023s: validate firmware size To: Laxman Acharya Padhya , Jonathan Cameron Cc: =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Yasin Lee , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260710142212.52225-1-acharyalaxman8848@gmail.com> Content-Language: en-US From: David Lechner In-Reply-To: <20260710142212.52225-1-acharyalaxman8848@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 7/10/26 9:22 AM, Laxman Acharya Padhya wrote: > hx9023s_send_cfg() copies the firmware into a counted flexible array and > then reads fixed offsets from the copied data before walking register/value > pairs starting at FW_DATA_OFFSET. A truncated firmware image can therefore > make the driver read past the copied buffer during probe-time configuration > loading. > > Reject firmware images that cannot contain the fixed header, reject images > too large for the u16 fw_size field, and validate that the advertised > register count fits in the remaining payload. > > Move release_firmware() to the callback so the firmware object is released > on all hx9023s_send_cfg() error paths. This could probably be considered a separate fix (and therefore separate patch) since it looks like there is an existing code path (return -ENOMEM) where it would not be released. > > Fixes: e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality") > Cc: stable@vger.kernel.org > Signed-off-by: Laxman Acharya Padhya > --- > drivers/iio/proximity/hx9023s.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c > index a6ff7cbe9e6..a2f9c077e58 100644 > --- a/drivers/iio/proximity/hx9023s.c > +++ b/drivers/iio/proximity/hx9023s.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -25,6 +26,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -1031,8 +1033,12 @@ static int hx9023s_bin_load(struct hx9023s_data *data, struct hx9023s_bin *bin) > > static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data) > { > - struct hx9023s_bin *bin __free(kfree) = > - kzalloc(fw->size + sizeof(*bin), GFP_KERNEL); > + struct hx9023s_bin *bin __free(kfree) = NULL; We don't initialize autocleanup variables to NULL. So leave this as-is and just put the size check before it. > + > + if (fw->size < FW_DATA_OFFSET || fw->size > U16_MAX) > + return -EINVAL; > + > + bin = kzalloc(sizeof(*bin) + fw->size, GFP_KERNEL); > if (!bin) > return -ENOMEM; > > @@ -1041,7 +1047,8 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data > bin->fw_ver = bin->data[FW_VER_OFFSET]; > bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET); > > - release_firmware(fw); > + if (bin->reg_count > (bin->fw_size - FW_DATA_OFFSET) / 2) > + return -EINVAL; > > return hx9023s_bin_load(data, bin); > } > @@ -1058,6 +1065,7 @@ static void hx9023s_cfg_update(const struct firmware *fw, void *context) > } > > ret = hx9023s_send_cfg(fw, data); > + release_firmware(fw); > if (ret) { > dev_warn(dev, "Firmware update failed: %d\n", ret); > goto no_fw; > > base-commit: 0e35b9b6ec0ffcc5e23cbdec09f5c622ad532b53