From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796355415; b=Z11GxfeuTXLNZ67UHAztEkYrOS6BkcIG/aiFL9p7IggBpoIkKWgPtFHw4AvJzxH1a9il 3S42UYdJbIB3v/iwFxp3H8baCIk21mvbxE80ZH8XE7EdlkOpYJk0jD5Wt5/BpgpWt7U2I U8+L8qCNpzA2uxqKO2ILmA7UmOoEwNi+rLkWkdcCOvZ1hTDlLYwKxr1bY5Dyn5ty7/91H cH0F18UFDvDxlCA2HQmXI5toAGMXkguDCQ8vyvI93FYgOM0MWO5zLaZrnMseRdUCKUQTc ftTmhknRs5xU7GaITsNr6nD2kl/vqZOh5sCIS++bIEpanh1AeR08t26eeRKLrbKrwSA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796355415; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=J7NNRvn/ty2j3WSXvpn33sRNHEwP0To/CpjqsXL49ks=; b=PC+XzYhhtjVdgpuN4y00uAuNL6G+3KXgPa/fxUKL235ZdWdMIR8+bqedNiXiagFu/25D OdNSrCMuwKNC9uV+oqPaqvPTZ+5ES7Jf279frfFZrDx0q31G3vlHCMvr4ohU7S0qynt8X I+LBvBUENTIPdoSlD7dk6lkjPcaZHolhlp7TgEyfaRla3DF9DGGJFm0NGa2No507MIjnW tw3/gJM4W4dLkuODn/eBgnG3VwheWpdZZlSRPJv1hmsTliz/ZwmmrZXeLQKi7aCerxD5s z+kx9vtK7zlJ5Cei9Ucp77hqWDQSFM0OPWqM/l0B2wBGXwFWs3OhcGxINiuM+EurLmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=GvDjU3Ol; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64779606A689; Fri, 4 Dec 2026 03:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=GvDjU3Ol Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D95F1F00897; Fri, 4 Dec 2026 03:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796355415; bh=J7NNRvn/ty2j3WSXvpn33sRNHEwP0To/CpjqsXL49ks=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=GvDjU3OltK2e2VLeaelSgzEIB4VL/w0SePwnBn3vCcuvUrgUaZAPLaBCtFDdReOS6 xoHNgyr9fafvu246V0qocrcMl72s/I1+U7Eg31ClJ+7k8Zs86nDrQCOnq/4/3XVHcM 8rxtTI0UWQHk+fsIH1LTUdReWDwoGvrvgODI00I4= Date: Thu, 3 Dec 2026 22:42:15 +0100 From: Greg Kroah-Hartman To: John Paul Adrian Glaubitz Cc: Karl Mehltretter , Geert Uytterhoeven , linux-usb@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] usb: r8a66597-hcd: fix buffer overflow on odd-length FIFO reads Message-ID: <2026120307-fanning-pursuable-6333@gregkh> References: <20261005212823.55737-1-kmehltretter@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Oct 13, 2026 at 07:07:54PM +0200, John Paul Adrian Glaubitz wrote: > Hi Greg, > > On Mon, 2026-10-05 at 23:28 +0200, Karl Mehltretter wrote: > > An external R8A66597 (pdata->on_chip is not set) is read through a 16-bit > > FIFO port. r8a66597_read_fifo() rounds the byte count up to whole words > > and passes that word count to ioread16_rep(), which stores two bytes for > > every word. For an odd byte count the last word puts one byte more into > > the buffer than packet_read() asked for. When the data ends at the end of > > the URB's transfer buffer, that byte is written behind the buffer. > > > > Enumerating a device is enough to trigger it. The USB core reads the > > configuration descriptor header into a 9-byte kmalloc() buffer and the > > driver stores 10 bytes. An SH7785LCR board booted with slub_debug=FZPU > > reports: > > > > [kmalloc Redzone overwritten] 0x820c4229-0x820c4229 @offset=553. First byte 0x9 instead of 0xcc > > BUG kmalloc-32 (Not tainted): Object corrupt > > Allocated in usb_get_configuration+0x12c/0x11d8 age=51 cpu=0 pid=10 > > Object 820c4220: 09 02 20 00 01 01 00 80 fa 09 cc cc cc cc cc cc > > > > Odd-sized HID report descriptors are overrun in the same way. Without > > slab debugging the byte ends up in the unused tail of a kmalloc() object. > > A transfer buffer that is embedded in a larger object has the byte after > > it overwritten. > > > > Section 2.8.5 of the R8A66597 datasheet tells software to discard the > > excess byte of the last 16-bit FIFO read when DTLN is odd. Read only the > > whole words into the buffer. Read the last word into a temporary and > > store only its first byte. Use ioread16_rep() for that word as well, so > > that the byte is taken in the same byte order as the words before it. > > > > Fixes: 5d3043586db4 ("USB: r8a66597-hcd: host controller driver for R8A66597") > > Cc: stable@vger.kernel.org > > Reported-by: John Paul Adrian Glaubitz > > Closes: https://lore.kernel.org/linux-sh/3bd32eaf159db61ed1d423e1d52a869b3689c682.camel@physik.fu-berlin.de/ > > Tested-by: John Paul Adrian Glaubitz > > Assisted-by: LLM > > Signed-off-by: Karl Mehltretter > > --- > > > > v2: > > - Simplify the handling of the last byte as suggested by Geert: no count > > variable, len & 1, and a plain byte store instead of a 1-byte memcpy(). > > - Reword the commit message and add the SLUB report from Adrian's board. > > - Add Adrian's Tested-by. It was given for v1. The FIFO accesses are the > > same in v2, only the copy of the last byte changed. > > > > v1: https://lore.kernel.org/r/20261002213225.27834-1-kmehltretter@gmail.com/ > > > > Adrian tested v1 on an SH7785LCR board. I tested v2 on a custom QEMU > > model of the board with 32-bit and 29-bit kernels and slub_debug=FZPU. > > Both report the overflow without the patch and not with it. > > > > drivers/usb/host/r8a66597.h | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h > > --- a/drivers/usb/host/r8a66597.h > > +++ b/drivers/usb/host/r8a66597.h > > @@ -179,8 +179,15 @@ static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597, > > len & 0x03); > > } > > } else { > > - len = (len + 1) / 2; > > - ioread16_rep(fifoaddr, buf, len); > > + ioread16_rep(fifoaddr, buf, len / 2); > > + > > + if (len & 1) { > > + u16 tmp; > > + > > + /* Keep the byte order of the string read above. */ > > + ioread16_rep(fifoaddr, &tmp, 1); > > + ((u8 *)buf)[len - 1] = *(u8 *)&tmp; > > + } > > } > > } > > > > Are you going to pick this up through your tree or shall I pick this up through > the sh-linux tree? I'll grab it now, thanks.