All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] staging: most: sound: implement improvements reported in code review
@ 2021-02-02 11:38 Christian Gromm
  2021-02-02 11:38 ` [PATCH 1/2] staging: most: sound: add sanity check for function argument Christian Gromm
  2021-02-02 11:38 ` [PATCH 2/2] staging: most: sound: use non-safe list iteration Christian Gromm
  0 siblings, 2 replies; 4+ messages in thread
From: Christian Gromm @ 2021-02-02 11:38 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch set fixes two problems found during code audit.

Christian Gromm (2):
  staging: most: sound: add sanity check for function argument
  staging: most: sound: use non-safe list iteration

 drivers/staging/most/sound/sound.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] staging: most: sound: add sanity check for function argument
  2021-02-02 11:38 [PATCH 0/2] staging: most: sound: implement improvements reported in code review Christian Gromm
@ 2021-02-02 11:38 ` Christian Gromm
  2021-02-02 15:34   ` Dan Carpenter
  2021-02-02 11:38 ` [PATCH 2/2] staging: most: sound: use non-safe list iteration Christian Gromm
  1 sibling, 1 reply; 4+ messages in thread
From: Christian Gromm @ 2021-02-02 11:38 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch zero checks the function parameter 'bytes' before doing the
subtraction to prevent memory corruption.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/sound/sound.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 3a1a590..953a4fe 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -86,6 +86,8 @@ static void swap_copy24(u8 *dest, const u8 *source, unsigned int bytes)
 {
 	unsigned int i = 0;
 
+	if (!bytes)
+		return;
 	while (i < bytes - 2) {
 		dest[i] = source[i + 2];
 		dest[i + 1] = source[i + 1];
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] staging: most: sound: use non-safe list iteration
  2021-02-02 11:38 [PATCH 0/2] staging: most: sound: implement improvements reported in code review Christian Gromm
  2021-02-02 11:38 ` [PATCH 1/2] staging: most: sound: add sanity check for function argument Christian Gromm
@ 2021-02-02 11:38 ` Christian Gromm
  1 sibling, 0 replies; 4+ messages in thread
From: Christian Gromm @ 2021-02-02 11:38 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch replaces the safe list iteration function with the
non-safe one, as no list element is being deleted.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/sound/sound.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 953a4fe..9e23b11 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -160,9 +160,9 @@ static struct channel *get_channel(struct most_interface *iface,
 				   int channel_id)
 {
 	struct sound_adapter *adpt = iface->priv;
-	struct channel *channel, *tmp;
+	struct channel *channel;
 
-	list_for_each_entry_safe(channel, tmp, &adpt->dev_list, list) {
+	list_for_each_entry(channel, &adpt->dev_list, list) {
 		if ((channel->iface == iface) && (channel->id == channel_id))
 			return channel;
 	}
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] staging: most: sound: add sanity check for function argument
  2021-02-02 11:38 ` [PATCH 1/2] staging: most: sound: add sanity check for function argument Christian Gromm
@ 2021-02-02 15:34   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-02-02 15:34 UTC (permalink / raw)
  To: Christian Gromm; +Cc: gregkh, driverdev-devel

On Tue, Feb 02, 2021 at 12:38:09PM +0100, Christian Gromm wrote:
> This patch zero checks the function parameter 'bytes' before doing the
> subtraction to prevent memory corruption.
> 
> Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/staging/most/sound/sound.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
> index 3a1a590..953a4fe 100644
> --- a/drivers/staging/most/sound/sound.c
> +++ b/drivers/staging/most/sound/sound.c
> @@ -86,6 +86,8 @@ static void swap_copy24(u8 *dest, const u8 *source, unsigned int bytes)
>  {
>  	unsigned int i = 0;
>  
> +	if (!bytes)
> +		return;
>  	while (i < bytes - 2) {

If "bytes == 1" then this will cause problems still.  "bytes - 2"
becomes UINT_MAX.  I mean probably that's not possible but we may as
well make the sanity check if (bytes < 2) just for readability.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-02 15:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 11:38 [PATCH 0/2] staging: most: sound: implement improvements reported in code review Christian Gromm
2021-02-02 11:38 ` [PATCH 1/2] staging: most: sound: add sanity check for function argument Christian Gromm
2021-02-02 15:34   ` Dan Carpenter
2021-02-02 11:38 ` [PATCH 2/2] staging: most: sound: use non-safe list iteration Christian Gromm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.