SPI omap2_mcspi.c: Check params before dereference or use
PATCH 1/6 SPI omap2_mcspi.c: Check params before dereference or use
This was previously submitted directly to the linux-kernel list. It was incomplete the first time because it failed to also check the chip_select value.
Check spi->controller_state before dereference.
Check spi->chip_select for range before use.
Neither are necessarily valid after spi_alloc_device() and then spi_add_device() fails. Calling spi_put_device() will trigger the error.
drivers/spi/omap2_mcspi.c | 30 +++++++++++++++++------------- 1 files changed, 17 insertions(+), 13 deletions(-)
drivers/spi/omap2_mcspi.c +17 -13
@@ -748,22 +748,26 @@ static void omap2_mcspi_cleanup(struct spi_device *spi)struct omap2_mcspi_dma *mcspi_dma;struct omap2_mcspi_cs *cs; - mcspi =spi_master_get_devdata (spi->master); - mcspi_dma = &mcspi->dma_channels[spi->chip_select]; +if (spi->controller_state) { +/* Unlink controller state from context save list */ + cs = spi->controller_state; +list_del (&cs->node); -/* Unlink controller state from context save list */ - cs = spi->controller_state; -list_del (&cs->node); +kfree (spi->controller_state); + } -kfree (spi->controller_state); +if (spi->chip_select < spi->master->num_chipselect) { + mcspi =spi_master_get_devdata (spi->master); + mcspi_dma = &mcspi->dma_channels[spi->chip_select]; -if (mcspi_dma->dma_rx_channel !=-1 ) { -omap_free_dma (mcspi_dma->dma_rx_channel); - mcspi_dma->dma_rx_channel =-1 ; - } -if (mcspi_dma->dma_tx_channel !=-1 ) { -omap_free_dma (mcspi_dma->dma_tx_channel); - mcspi_dma->dma_tx_channel =-1 ; +if (mcspi_dma->dma_rx_channel !=-1 ) { +omap_free_dma (mcspi_dma->dma_rx_channel); + mcspi_dma->dma_rx_channel =-1 ; + } +if (mcspi_dma->dma_tx_channel !=-1 ) { +omap_free_dma (mcspi_dma->dma_tx_channel); + mcspi_dma->dma_tx_channel =-1 ; + } } }
Quoted 4 lines · Scott Ellis
This was previously submitted directly to the linux-kernel list. It was incomplete the first time because it failed to also check the
chip_selectvalue.
Quoted 8 lines
Check
spi->controller_statebefore dereference.
Checkspi->chip_selectfor range before use.Neither are necessarily valid after
spi_alloc_device()and thenspi_add_device()fails. Callingspi_put_device()will trigger the error.Signed-off-by Scott Ellis <[email protected]>
Hi Scott,
Can you please respin and repost your pending patches on top of 2.6.34? The current patches don't apply as-is and I've lost track of what needs to be done.
Thanks,
g.
Quoted 56 lines
drivers/spi/omap2_mcspi.c | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)drivers/spi/omap2_mcspi.c +17
-13@@ -748,22 +748,26 @@ static void omap2_mcspi_cleanup(struct spi_device *spi) struct omap2_mcspi_dma *mcspi_dma; struct omap2_mcspi_cs *cs; - mcspi = spi_master_get_devdata(spi->master); - mcspi_dma = &mcspi->dma_channels[spi->chip_select]; + if (spi->controller_state) { + /* Unlink controller state from context save list */ + cs = spi->controller_state; + list_del(&cs->node); - /* Unlink controller state from context save list */ - cs = spi->controller_state; - list_del(&cs->node); + kfree(spi->controller_state); + } - kfree(spi->controller_state); + if (spi->chip_select < spi->master->num_chipselect) { + mcspi = spi_master_get_devdata(spi->master); + mcspi_dma = &mcspi->dma_channels[spi->chip_select]; - if (mcspi_dma->dma_rx_channel != -1) { - omap_free_dma(mcspi_dma->dma_rx_channel); - mcspi_dma->dma_rx_channel = -1; - } - if (mcspi_dma->dma_tx_channel != -1) { - omap_free_dma(mcspi_dma->dma_tx_channel); - mcspi_dma->dma_tx_channel = -1; + if (mcspi_dma->dma_rx_channel != -1) { + omap_free_dma(mcspi_dma->dma_rx_channel); + mcspi_dma->dma_rx_channel = -1; + } + if (mcspi_dma->dma_tx_channel != -1) { + omap_free_dma(mcspi_dma->dma_tx_channel); + mcspi_dma->dma_tx_channel = -1; + } } }
Signature · 6 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): AANLkTikCydr_Nj446sySru774pY2jXLKNUNVfW3LSK9R-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Check spi->chip_select for range before use.
The spi->controller_state check is already in 2.6.34-rc7
drivers/spi/omap2_mcspi.c | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-)
drivers/spi/omap2_mcspi.c +0 -0
@@ -755,7 +755,6 @@ static void omap2_mcspi_cleanup(struct spi_device
*spi)
struct omap2_mcspi_cs *cs;
mcspi = spi_master_get_devdata(spi->master);
- mcspi_dma = &mcspi->dma_channels[spi->chip_select];
if (spi->controller_state) {
/* Unlink controller state from context save list */
@@ -765,13 +764,17 @@ static void omap2_mcspi_cleanup(struct spi_device *spi)
kfree(spi->controller_state);
}
- if (mcspi_dma->dma_rx_channel != -1) {
- omap_free_dma(mcspi_dma->dma_rx_channel);
- mcspi_dma->dma_rx_channel = -1;
- }
- if (mcspi_dma->dma_tx_channel != -1) {
- omap_free_dma(mcspi_dma->dma_tx_channel);
- mcspi_dma->dma_tx_channel = -1;
+ if (spi->chip_select < spi->master->num_chipselect) {
+ mcspi_dma = &mcspi->dma_channels[spi->chip_select];
+
+ if (mcspi_dma->dma_rx_channel != -1) {
+ omap_free_dma(mcspi_dma->dma_rx_channel);
+ mcspi_dma->dma_rx_channel = -1;
+ }
+ if (mcspi_dma->dma_tx_channel != -1) {
+ omap_free_dma(mcspi_dma->dma_tx_channel);
+ mcspi_dma->dma_tx_channel = -1;
+ }
}
}
------------------------------------------------------------------------------
Quoted 5 lines · Scott Ellis
Check
spi->chip_selectfor range before use.The
spi->controller_statecheck is already in 2.6.34-rc7Signed-off-by Scott Ellis <[email protected]>
Okay, I've pick up this patch, but please check your Evolution configuration. Patchwork seems to be barfing on the patches sent by you. My guess is that it relies on a "---" line between the last "signed-off-by", and the start of the actual patch. See here to see what I'm talking about:
https://patchwork.kernel.org/patch/101890/
Cheers,
g.
Quoted 44 lines
drivers/spi/omap2_mcspi.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)drivers/spi/omap2_mcspi.c +0
-1@@ -755,7 +755,6 @@ static void omap2_mcspi_cleanup(struct spi_device *spi) struct omap2_mcspi_cs *cs; mcspi = spi_master_get_devdata(spi->master); - mcspi_dma = &mcspi->dma_channels[spi->chip_select]; if (spi->controller_state) {/* Unlink controller state from context save list */
drivers/spi/omap2_mcspi.c +11
-7@@ -765,13 +764,17 @@ static void omap2_mcspi_cleanup(struct spi_device *spi) kfree(spi->controller_state); } - if (mcspi_dma->dma_rx_channel != -1) { - omap_free_dma(mcspi_dma->dma_rx_channel); - mcspi_dma->dma_rx_channel = -1; - } - if (mcspi_dma->dma_tx_channel != -1) { - omap_free_dma(mcspi_dma->dma_tx_channel); - mcspi_dma->dma_tx_channel = -1; + if (spi->chip_select < spi->master->num_chipselect) { + mcspi_dma = &mcspi->dma_channels[spi->chip_select]; + + if (mcspi_dma->dma_rx_channel != -1) { + omap_free_dma(mcspi_dma->dma_rx_channel); + mcspi_dma->dma_rx_channel = -1; + } + if (mcspi_dma->dma_tx_channel != -1) { + omap_free_dma(mcspi_dma->dma_tx_channel); + mcspi_dma->dma_tx_channel = -1; + } } }
Signature · 6 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html