• Nicolas Iooss's avatar
    net: ax88796c: do not receive data in pointer · f93fd0ca
    Nicolas Iooss authored
    Function axspi_read_status calls:
    
        ret = spi_write_then_read(ax_spi->spi, ax_spi->cmd_buf, 1,
                                  (u8 *)&status, 3);
    
    status is a pointer to a struct spi_status, which is 3-byte wide:
    
        struct spi_status {
            u16 isr;
            u8 status;
        };
    
    But &status is the pointer to this pointer, and spi_write_then_read does
    not dereference this parameter:
    
        int spi_write_then_read(struct spi_device *spi,
                                const void *txbuf, unsigned n_tx,
                                void *rxbuf, unsigned n_rx)
    
    Therefore axspi_read_status currently receive a SPI response in the
    pointer status, which overwrites 24 bits of the pointer.
    
    Thankfully, on Little-Endian systems, the pointer is only used in
    
        le16_to_cpus(&status->isr);
    
    ... which is a no-operation. So there, the overwritten pointer is not
    dereferenced. Nevertheless on Big-Endian systems, this can lead to
    dereferencing pointers after their 24 most signific...
    f93fd0ca
ax88796c_spi.c 2.86 KB