All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Lee Jones <lee@kernel.org>
Cc: Hans de Goede <hansg@kernel.org>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	Jeff LaBundy <jeff@labundy.com>,
	 Jens Reidel <adrian@mainlining.org>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org
Subject: Re: [PATCH 10/10] Input: goodix_berlin_spi - validate ic_data and SPI max transfer size
Date: Sat, 28 Nov 2026 22:27:14 -0800	[thread overview]
Message-ID: <awvFK8MEL5shuSjR@google.com> (raw)
In-Reply-To: <20261127201050.3532488-11-lee@kernel.org>

Hi Lee,

On Fri, Nov 27, 2026 at 08:10:04PM +0000, Lee Jones wrote:
> goodix_berlin_spi_probe() dereferences ic_data without checking
> spi_get_device_match_data() for NULL, and subtracts the SPI read and
> write prefix lengths from spi_max_transfer_size() without checking that
> max_size exceeds both prefix lengths.  A controller reporting a small
> maximum transfer size causes an unsigned size_t underflow (or zero
> max_raw_read/write), bypassing regmap transfer chunking.
> 
> Return -EINVAL if ic_data is NULL or if max_size is not strictly greater
> than both the read and write prefix lengths.
> 
> Fixes: 3aa182bbc5b6 ("Input: goodix-berlin - add SPI support for Goodix Berlin Touchscreen IC")
> Fixes: 4d395cb071a3 ("Input: goodix_berlin - add support for Berlin-A series")
> Closes: https://sashiko.dev/#/bug/linux-a8b8e506-08b4-44c4-bf67-3c8ef31c6da7
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
>  drivers/input/touchscreen/goodix_berlin_spi.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/goodix_berlin_spi.c b/drivers/input/touchscreen/goodix_berlin_spi.c
> index 01f850f484c2..377c81a3e3c5 100644
> --- a/drivers/input/touchscreen/goodix_berlin_spi.c
> +++ b/drivers/input/touchscreen/goodix_berlin_spi.c
> @@ -133,6 +133,9 @@ static int goodix_berlin_spi_probe(struct spi_device *spi)
>  	size_t max_size;
>  	int error = 0;
>  
> +	if (!ic_data)
> +		return -EINVAL;
> +

I think it is still open question if we want to stop this at driver core
or bus levels or litter each and every driver. I'll sit on this for now:
the operation is privileged so it is just users shooting themselves in
their foot.

>  	spi->mode = SPI_MODE_0;
>  	spi->bits_per_word = 8;
>  	error = spi_setup(spi);
> @@ -140,6 +143,9 @@ static int goodix_berlin_spi_probe(struct spi_device *spi)
>  		return error;
>  
>  	max_size = spi_max_transfer_size(spi);
> +	if (max_size <= max_t(size_t, ic_data->read_prefix_len,
> +			      GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN))
> +		return -EINVAL;

Could you please split this out so I can commit this separately.

>  
>  	regmap_config = goodix_berlin_spi_regmap_conf;
>  	regmap_config.max_raw_read = max_size - ic_data->read_prefix_len;

Thanks.

-- 
Dmitry

      reply	other threads:[~2026-11-29  6:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 20:09 [PATCH 00/10] Input: Fix OOB writes, UAFs, NULL derefs, and suspend work bugs (batch 2) Lee Jones
2026-11-27 20:09 ` [PATCH 01/10] Input: adi - prevent off-by-one write in adi_read_packet() Lee Jones
2026-11-30  5:42   ` Dmitry Torokhov
2026-11-27 20:09 ` [PATCH 02/10] Input: adi - validate axis and button counts in adi_id_decode() Lee Jones
2026-11-30  5:42   ` Dmitry Torokhov
2026-11-27 20:09 ` [PATCH 03/10] Input: xpad - cancel presence work on xpad360w_start_input() failure Lee Jones
2026-11-27 20:24   ` sashiko-bot
2026-11-27 20:09 ` [PATCH 04/10] Input: aw86927 - use devm_work_autocancel() for haptics play work Lee Jones
2026-11-27 20:09 ` [PATCH 05/10] Input: stmfts - fix i2c_smbus_read_i2c_block_data() check in status sysfs Lee Jones
2026-11-27 20:35   ` David Heidelberg
2026-11-28  6:09   ` Dmitry Torokhov
2026-11-27 20:10 ` [PATCH 06/10] Input: xen-kbdfront - check info->ptr and info->kbd before dereferencing Lee Jones
2026-11-30  6:04   ` Dmitry Torokhov
2026-11-27 20:10 ` [PATCH 07/10] Input: drv2665 - disable haptics work across suspend and resume Lee Jones
2026-11-27 20:10 ` [PATCH 08/10] Input: drv2667 " Lee Jones
2026-11-27 20:10 ` [PATCH 09/10] Input: goodix_berlin_i2c - check i2c_get_match_data() for NULL Lee Jones
2026-11-27 20:10 ` [PATCH 10/10] Input: goodix_berlin_spi - validate ic_data and SPI max transfer size Lee Jones
2026-11-29  6:27   ` Dmitry Torokhov [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=awvFK8MEL5shuSjR@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=adrian@mainlining.org \
    --cc=hansg@kernel.org \
    --cc=jeff@labundy.com \
    --cc=lee@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neil.armstrong@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.