* [PATCH] staging: most: don't access hdm_ch before checking it valid
@ 2020-09-28 10:48 Jing Xiangfeng
2020-09-28 11:48 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Jing Xiangfeng @ 2020-09-28 10:48 UTC (permalink / raw)
To: gregkh, christian.gromm, masahiroy, tglx, keescook
Cc: devel, linux-kernel, jingxiangfeng
In try_start_dim_transfer(), pointer hdm_ch is accessed before checking.
This may lead to a potential null pointer dereference. Fix this by
dereferencing hdm_ch after calling BUG_ON().
Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
---
drivers/staging/most/dim2/dim2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index 509c8012d20b..ccd7cc7545e4 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -148,7 +148,7 @@ void dimcb_on_error(u8 error_id, const char *error_message)
static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
{
u16 buf_size;
- struct list_head *head = &hdm_ch->pending_list;
+ struct list_head *head;
struct mbo *mbo;
unsigned long flags;
struct dim_ch_state_t st;
@@ -156,6 +156,7 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
BUG_ON(!hdm_ch);
BUG_ON(!hdm_ch->is_initialized);
+ head = &hdm_ch->pending_list;
spin_lock_irqsave(&dim_lock, flags);
if (list_empty(head)) {
spin_unlock_irqrestore(&dim_lock, flags);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: most: don't access hdm_ch before checking it valid
2020-09-28 10:48 [PATCH] staging: most: don't access hdm_ch before checking it valid Jing Xiangfeng
@ 2020-09-28 11:48 ` Dan Carpenter
2020-09-29 1:01 ` Jing Xiangfeng
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2020-09-28 11:48 UTC (permalink / raw)
To: Jing Xiangfeng
Cc: gregkh, christian.gromm, masahiroy, tglx, keescook, devel, linux-kernel
On Mon, Sep 28, 2020 at 06:48:38PM +0800, Jing Xiangfeng wrote:
> In try_start_dim_transfer(), pointer hdm_ch is accessed before checking.
> This may lead to a potential null pointer dereference. Fix this by
> dereferencing hdm_ch after calling BUG_ON().
>
> Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
> ---
> drivers/staging/most/dim2/dim2.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
> index 509c8012d20b..ccd7cc7545e4 100644
> --- a/drivers/staging/most/dim2/dim2.c
> +++ b/drivers/staging/most/dim2/dim2.c
> @@ -148,7 +148,7 @@ void dimcb_on_error(u8 error_id, const char *error_message)
> static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
> {
> u16 buf_size;
> - struct list_head *head = &hdm_ch->pending_list;
This is not a dereference, it's just pointer math. In other words:
struct list_head *head = hdm_ch + offsetof(struct hdm_channel, pending_list);
So the commit message is wrong because this cannot lead to a NULL
dereference. It's better to just delete the BUG_ON(). We don't really
like BUG_ON(). Checkpatch will complain about them. An Oops gives
basically the same information as a BUG_ON() without completely killing
the kernel so just dereferencing a NULL is preferable. Finally, we can
see from the callers that "hdm_ch" is never NULL.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: most: don't access hdm_ch before checking it valid
2020-09-28 11:48 ` Dan Carpenter
@ 2020-09-29 1:01 ` Jing Xiangfeng
0 siblings, 0 replies; 3+ messages in thread
From: Jing Xiangfeng @ 2020-09-29 1:01 UTC (permalink / raw)
To: Dan Carpenter
Cc: gregkh, christian.gromm, masahiroy, tglx, keescook, devel, linux-kernel
On 2020/9/28 19:48, Dan Carpenter wrote:
> On Mon, Sep 28, 2020 at 06:48:38PM +0800, Jing Xiangfeng wrote:
>> In try_start_dim_transfer(), pointer hdm_ch is accessed before checking.
>> This may lead to a potential null pointer dereference. Fix this by
>> dereferencing hdm_ch after calling BUG_ON().
>>
>> Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
>> ---
>> drivers/staging/most/dim2/dim2.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
>> index 509c8012d20b..ccd7cc7545e4 100644
>> --- a/drivers/staging/most/dim2/dim2.c
>> +++ b/drivers/staging/most/dim2/dim2.c
>> @@ -148,7 +148,7 @@ void dimcb_on_error(u8 error_id, const char *error_message)
>> static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
>> {
>> u16 buf_size;
>> - struct list_head *head = &hdm_ch->pending_list;
> This is not a dereference, it's just pointer math. In other words:
>
> struct list_head *head = hdm_ch + offsetof(struct hdm_channel, pending_list);
Thanks for correcting!
>
> So the commit message is wrong because this cannot lead to a NULL
> dereference. It's better to just delete the BUG_ON(). We don't really
> like BUG_ON(). Checkpatch will complain about them. An Oops gives
> basically the same information as a BUG_ON() without completely killing
> the kernel so just dereferencing a NULL is preferable. Finally, we can
> see from the callers that "hdm_ch" is never NULL.
>
> regards,
> dan carpenter
>
> .
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-29 1:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-28 10:48 [PATCH] staging: most: don't access hdm_ch before checking it valid Jing Xiangfeng
2020-09-28 11:48 ` Dan Carpenter
2020-09-29 1:01 ` Jing Xiangfeng
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).