* [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree()
@ 2019-07-23 13:40 Jia-Ju Bai
2019-07-23 13:47 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-23 13:40 UTC (permalink / raw)
To: perex, tiwai, huangfq.daxian, tglx, allison
Cc: alsa-devel, linux-kernel, Jia-Ju Bai
In snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74
to check whether block->next is NULL:
if (block->next)
When block->next is NULL, block->next is used on line 84:
block->next->prev = block->prev;
Thus, a possible null-pointer dereference may occur in this case.
To fix this possible bug, block->next is checked before using it.
This bug is found by a static analysis tool STCheck written by us.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
sound/isa/gus/gus_mem.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c
index cb02d18dde60..ed6205b88057 100644
--- a/sound/isa/gus/gus_mem.c
+++ b/sound/isa/gus/gus_mem.c
@@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * blo
if (block->prev)
block->prev->next = NULL;
} else {
- block->next->prev = block->prev;
+ if (block->next)
+ block->next->prev = block->prev;
if (block->prev)
block->prev->next = block->next;
}
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree()
2019-07-23 13:40 [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree() Jia-Ju Bai
@ 2019-07-23 13:47 ` Takashi Iwai
2019-07-23 13:51 ` Jia-Ju Bai
0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2019-07-23 13:47 UTC (permalink / raw)
To: Jia-Ju Bai; +Cc: huangfq.daxian, tglx, allison, perex, alsa-devel, linux-kernel
On Tue, 23 Jul 2019 15:40:20 +0200,
Jia-Ju Bai wrote:
>
> In snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74
> to check whether block->next is NULL:
> if (block->next)
>
> When block->next is NULL, block->next is used on line 84:
> block->next->prev = block->prev;
>
> Thus, a possible null-pointer dereference may occur in this case.
There is already a check beforehand:
if (alloc->last == block) {
and the code path you're referring to is only after this check fails,
i.e. it's no last entry, hence block->next can be never NULL.
So the current code is OK.
thanks,
Takashi
>
> To fix this possible bug, block->next is checked before using it.
>
> This bug is found by a static analysis tool STCheck written by us.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
> sound/isa/gus/gus_mem.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c
> index cb02d18dde60..ed6205b88057 100644
> --- a/sound/isa/gus/gus_mem.c
> +++ b/sound/isa/gus/gus_mem.c
> @@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * blo
> if (block->prev)
> block->prev->next = NULL;
> } else {
> - block->next->prev = block->prev;
> + if (block->next)
> + block->next->prev = block->prev;
> if (block->prev)
> block->prev->next = block->next;
> }
> --
> 2.17.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree()
2019-07-23 13:47 ` Takashi Iwai
@ 2019-07-23 13:51 ` Jia-Ju Bai
0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-23 13:51 UTC (permalink / raw)
To: Takashi Iwai
Cc: huangfq.daxian, tglx, allison, perex, alsa-devel, linux-kernel
Thanks for the quick reply :)
I think you are right, and I did not consider "if (alloc->last == block)"
Sorry for the false report...
Best wishes,
Jia-Ju Bai
On 2019/7/23 21:47, Takashi Iwai wrote:
> On Tue, 23 Jul 2019 15:40:20 +0200,
> Jia-Ju Bai wrote:
>> In snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74
>> to check whether block->next is NULL:
>> if (block->next)
>>
>> When block->next is NULL, block->next is used on line 84:
>> block->next->prev = block->prev;
>>
>> Thus, a possible null-pointer dereference may occur in this case.
> There is already a check beforehand:
>
> if (alloc->last == block) {
>
> and the code path you're referring to is only after this check fails,
> i.e. it's no last entry, hence block->next can be never NULL.
>
> So the current code is OK.
>
>
> thanks,
>
> Takashi
>
>> To fix this possible bug, block->next is checked before using it.
>>
>> This bug is found by a static analysis tool STCheck written by us.
>>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> ---
>> sound/isa/gus/gus_mem.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c
>> index cb02d18dde60..ed6205b88057 100644
>> --- a/sound/isa/gus/gus_mem.c
>> +++ b/sound/isa/gus/gus_mem.c
>> @@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * blo
>> if (block->prev)
>> block->prev->next = NULL;
>> } else {
>> - block->next->prev = block->prev;
>> + if (block->next)
>> + block->next->prev = block->prev;
>> if (block->prev)
>> block->prev->next = block->next;
>> }
>> --
>> 2.17.0
>>
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-23 13:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 13:40 [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree() Jia-Ju Bai
2019-07-23 13:47 ` Takashi Iwai
2019-07-23 13:51 ` Jia-Ju Bai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).