diff mbox series

crypto: iaa - Fix potential use after free bug

Message ID e049271f-41f2-4d04-ac69-80186f2eecd9@stanley.mountain (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series crypto: iaa - Fix potential use after free bug | expand

Commit Message

Dan Carpenter July 24, 2024, 4:09 p.m. UTC
The free_device_compression_mode(iaa_device, device_mode) function frees
"device_mode" but it iss passed to iaa_compression_modes[i]->free() a few
lines later resulting in a use after free.

The good news is that, so far as I can tell, nothing implements the
->free() function and the use after free happens in dead code.  But, with
this fix, when something does implement it, we'll be ready.  :)

Fixes: b190447e0fa3 ("crypto: iaa - Add compression mode management along with fixed mode")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Zanussi, Tom July 29, 2024, 4:40 p.m. UTC | #1
Hi Dan,

On Wed, 2024-07-24 at 11:09 -0500, Dan Carpenter wrote:
> The free_device_compression_mode(iaa_device, device_mode) function
> frees
> "device_mode" but it iss passed to iaa_compression_modes[i]->free() a
> few
> lines later resulting in a use after free.
> 
> The good news is that, so far as I can tell, nothing implements the
> ->free() function and the use after free happens in dead code.  But,
> with
> this fix, when something does implement it, we'll be ready.  :)
> 

Good catch, thanks for fixing this.

Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com>


> Fixes: b190447e0fa3 ("crypto: iaa - Add compression mode management
> along with fixed mode")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/crypto/intel/iaa/iaa_crypto_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c
> b/drivers/crypto/intel/iaa/iaa_crypto_main.c
> index e810d286ee8c..237f87000070 100644
> --- a/drivers/crypto/intel/iaa/iaa_crypto_main.c
> +++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c
> @@ -495,10 +495,10 @@ static void
> remove_device_compression_modes(struct iaa_device *iaa_device)
>                 if (!device_mode)
>                         continue;
>  
> -               free_device_compression_mode(iaa_device,
> device_mode);
> -               iaa_device->compression_modes[i] = NULL;
>                 if (iaa_compression_modes[i]->free)
>                         iaa_compression_modes[i]->free(device_mode);
> +               free_device_compression_mode(iaa_device,
> device_mode);
> +               iaa_device->compression_modes[i] = NULL;
>         }
>  }
>
Herbert Xu Aug. 2, 2024, 1:16 p.m. UTC | #2
On Wed, Jul 24, 2024 at 11:09:43AM -0500, Dan Carpenter wrote:
> The free_device_compression_mode(iaa_device, device_mode) function frees
> "device_mode" but it iss passed to iaa_compression_modes[i]->free() a few
> lines later resulting in a use after free.
> 
> The good news is that, so far as I can tell, nothing implements the
> ->free() function and the use after free happens in dead code.  But, with
> this fix, when something does implement it, we'll be ready.  :)
> 
> Fixes: b190447e0fa3 ("crypto: iaa - Add compression mode management along with fixed mode")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/crypto/intel/iaa/iaa_crypto_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c
index e810d286ee8c..237f87000070 100644
--- a/drivers/crypto/intel/iaa/iaa_crypto_main.c
+++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c
@@ -495,10 +495,10 @@  static void remove_device_compression_modes(struct iaa_device *iaa_device)
 		if (!device_mode)
 			continue;
 
-		free_device_compression_mode(iaa_device, device_mode);
-		iaa_device->compression_modes[i] = NULL;
 		if (iaa_compression_modes[i]->free)
 			iaa_compression_modes[i]->free(device_mode);
+		free_device_compression_mode(iaa_device, device_mode);
+		iaa_device->compression_modes[i] = NULL;
 	}
 }