Re: [PATCH] firewire: core: bound traversal stack in read_config_rom()

Greg KH <[email protected]> Tue, 2 Sep 2025 06:49:45 +0200
Newsgroups gmane.linux.kernel,gmane.linux.kernel.firewire.devel
Message-ID <2025090237-undocked-reopen-7ce6@gregkh>
On Mon, Sep 01, 2025 at 07:15:47PM +0200, Aleksandr Shabelnikov wrote:
> read_config_rom() walks Configuration ROM directories using an explicit
> stack but pushes new entries without a bound check:
> 
>     stack[sp++] = i + rom[i];
> 
> A malicious or malformed Configuration ROM can construct in-range cyclic
> directory references so that the traversal keeps enqueueing, growing the
> stack past its allocated depth. rom[] and stack[] are allocated adjacent
> in a single kmalloc() block, so this leads to a heap out-of-bounds write.
> 
> Add a hard bound check before every push. While this does not itself
> implement cycle detection, it prevents memory corruption and limits the
> impact to a clean failure (-EOVERFLOW).
> 
> Reported-by: Aleksandr Shabelnikov <[email protected]>
> Suggested-by: Aleksandr Shabelnikov <[email protected]>
> 
> Signed-off-by: Aleksandr Shabelnikov <[email protected]>

Nit, you only need the last one "reported-by" and "suggested-by" don't
mean anything when it is you as the author and signed-off-by line :)

thanks,

greg k-h