From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECF5C269819; Tue, 8 Apr 2025 12:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744114752; cv=none; b=WwYCmLNpl4RdaK2qGLaJ+gMGP64AqChplZU5PqvF+iakpmVIUkTemnM8rZzxOdq0aRFDZOq3JQeBgFoDUJ04KLHmg+uYvlvUnBYtDpue52F/xbl5F7UurzMtFyOmXI41z4/0uW4oWJwwprtK7xbJMKt7xTidBAgwyVI6xxLS+EU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744114752; c=relaxed/simple; bh=uIVMioTSCw3PM0SMtoqo+MPRCtZGRw0747nkJY7FjTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b1bF2N2iIPApOQ40ieZ4RU6QHvavpQ0tGqHdMoQ/b9z80l8Y7Yzt32P5XiDd/CtF7HiJRbOHvigYLmyeTw5zBuxw+NUlu8mF1Sj/oGq7p9NhXSi2tmuSeLLjYoWNJOrmI/zxo0qpsgT9WHqn91rDnIKa/S9yi+qsNRPj7o3XFsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=db8/Kqxx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="db8/Kqxx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5500EC4CEE5; Tue, 8 Apr 2025 12:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744114751; bh=uIVMioTSCw3PM0SMtoqo+MPRCtZGRw0747nkJY7FjTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=db8/KqxxWR0zgnQprnzpP2m7lUlBlvU4v7mbMiqAEUqvSZu7nSnVhUDdF+9in3lZi avGg/LgxISUjYD7zxbgPWJnqxgPtW0atGzJbPx2mHuBgwPeaI5rfhEeaQPRIMUj7i0 CiujZlLgiZZ9rc+iXg7UmlbzZzw2twBqLuCp8ixQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Nuno=20S=C3=A1?= , David Lechner , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.13 223/499] iio: backend: make sure to NULL terminate stack buffer Date: Tue, 8 Apr 2025 12:47:15 +0200 Message-ID: <20250408104856.772269092@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104851.256868745@linuxfoundation.org> References: <20250408104851.256868745@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nuno Sá [ Upstream commit 035b4989211dc1c8626e186d655ae8ca5141bb73 ] Make sure to NULL terminate the buffer in iio_backend_debugfs_write_reg() before passing it to sscanf(). It is a stack variable so we should not assume it will 0 initialized. Fixes: cdf01e0809a4 ("iio: backend: add debugFs interface") Signed-off-by: Nuno Sá Reviewed-by: David Lechner Link: https://patch.msgid.link/20250218-dev-iio-misc-v1-1-bf72b20a1eb8@analog.com Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/industrialio-backend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index 3632812720352..aa2b8b38ab587 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -155,10 +155,12 @@ static ssize_t iio_backend_debugfs_write_reg(struct file *file, ssize_t rc; int ret; - rc = simple_write_to_buffer(buf, sizeof(buf), ppos, userbuf, count); + rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, count); if (rc < 0) return rc; + buf[count] = '\0'; + ret = sscanf(buf, "%i %i", &back->cached_reg_addr, &val); switch (ret) { -- 2.39.5