Skip to content

Commit e957c96

Browse files
dlechbroonie
authored andcommitted
spi: offload: fix use after free
Fix a use after free bug in devm_spi_offload_get() where a pointer was dereferenced after being freed. Instead, add a new local variable to avoid needing to use the resource pointer to access the offload pointer. Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Fixes: 5a19e19 ("spi: axi-spi-engine: implement offload support") Signed-off-by: David Lechner <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d795a05 commit e957c96

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/spi/spi-offload.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct spi_offload *devm_spi_offload_get(struct device *dev,
108108
const struct spi_offload_config *config)
109109
{
110110
struct spi_controller_and_offload *resource;
111+
struct spi_offload *offload;
111112
int ret;
112113

113114
if (!spi || !config)
@@ -120,18 +121,20 @@ struct spi_offload *devm_spi_offload_get(struct device *dev,
120121
if (!resource)
121122
return ERR_PTR(-ENOMEM);
122123

123-
resource->controller = spi->controller;
124-
resource->offload = spi->controller->get_offload(spi, config);
125-
if (IS_ERR(resource->offload)) {
124+
offload = spi->controller->get_offload(spi, config);
125+
if (IS_ERR(offload)) {
126126
kfree(resource);
127-
return resource->offload;
127+
return offload;
128128
}
129129

130+
resource->controller = spi->controller;
131+
resource->offload = offload;
132+
130133
ret = devm_add_action_or_reset(dev, spi_offload_put, resource);
131134
if (ret)
132135
return ERR_PTR(ret);
133136

134-
return resource->offload;
137+
return offload;
135138
}
136139
EXPORT_SYMBOL_GPL(devm_spi_offload_get);
137140

0 commit comments

Comments
 (0)