Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: joshua.crofts1@gmail.com
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Gregor Boirie" <gregor.boirie@parrot.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sashiko <sashiko-bot@kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH] iio: magnetometer: ak8975: fix potential kernel stack memory leak
Date: Fri, 15 May 2026 12:50:30 +0300	[thread overview]
Message-ID: <agbsZs8UorOLzyhd@ashevche-desk.local> (raw)
In-Reply-To: <20260514-magnetometer-kernel-mem-leak-v1-1-35b48d699faf@gmail.com>

On Thu, May 14, 2026 at 01:38:17PM +0200, Joshua Crofts via B4 Relay wrote:

> Currently in the AK8975 driver there are two instances where potential
> uninitialized kernel stack memory leaks can occur. If
> i2c_smbus_read_i2c_block_data_or_emulated() returns a value less than
> the size of the buffer, uninitialized bytes are retained in the buffer
> and later the buffer is passed on to IIO buffers, potentially leaking
> memory to userspace.
> 
> Fix this by adding checks whether the return value of the function is
> equal to the size of the buffer and subsequently if the value is
> lesser than zero to distinguish from a returned error code.

...

> -	if (ret < 0)
> +	if (ret != sizeof(rval)) {
> +		if (ret >= 0)
> +			ret = -EIO;
>  		goto exit;
> +	}

Still better to not mix the two

	if (ret < 0)
		goto exit;
	if (ret != sizeof(rval)) {
		ret = -EIO;
		goto exit;
	}

...

Ditto for the second case.

-- 
With Best Regards,
Andy Shevchenko



      parent reply	other threads:[~2026-05-15  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-14 11:38 [PATCH] iio: magnetometer: ak8975: fix potential kernel stack memory leak Joshua Crofts via B4 Relay
2026-05-15  9:00 ` Joshua Crofts
2026-05-15  9:51   ` Andy Shevchenko
2026-05-15 10:11     ` Joshua Crofts
2026-05-15  9:50 ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=agbsZs8UorOLzyhd@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gregor.boirie@parrot.com \
    --cc=jic23@kernel.org \
    --cc=joshua.crofts1@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox