From: Tuo Li <islituo@gmail.com>
To: mchehab@kernel.org, yongsuyoo0215@gmail.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
baijiaju1990@outlook.com, Tuo Li <islituo@gmail.com>,
BassCheck <bass@buaa.edu.cn>
Subject: [PATCH] media: dvb-core: Fix a possible null-pointer dereference due to data race in dvbdmx_write()
Date: Wed, 8 Nov 2023 17:13:00 +0800 [thread overview]
Message-ID: <20231108091300.3124649-1-islituo@gmail.com> (raw)
The struct field dmx_demux.frontend is often protected by the lock
dvb_demux.mutex when is accessed. Here is an example in
dvbdmx_connect_frontend():
mutex_lock(&dvbdemux->mutex);
demux->frontend = frontend;
mutex_unlock(&dvbdemux->mutex);
However, the variable demux->frontend is accessed without holding the lock
dvbdemux->mutex in dvbdmx_write():
if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
In my opinion, this may be a harmful race, because if demux->fontend is set
to NULL right after the first condition is checked, a null-pointer
dereference can occur when accessing the field demux->frontend->source.
To fix this possible null-pointer dereference caused by data race, a lock
and unlock pair is added when accessing the variable demux->frontend.
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/media/dvb-core/dvb_demux.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c
index 7c4d86bfdd6c..791db667e2ed 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -1141,8 +1141,11 @@ static int dvbdmx_write(struct dmx_demux *demux, const char __user *buf, size_t
struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
void *p;
- if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
+ mutex_lock(&dvbdemux->mutex);
+ if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) {
+ mutex_unlock(&dvbdemux->mutex);
return -EINVAL;
+ }
p = memdup_user(buf, count);
if (IS_ERR(p))
--
2.34.1
next reply other threads:[~2023-11-08 9:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 9:13 Tuo Li [this message]
2023-11-09 8:02 ` [PATCH] media: dvb-core: Fix a possible null-pointer dereference due to data race in dvbdmx_write() Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2023-06-26 2:44 Tuo Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231108091300.3124649-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=baijiaju1990@outlook.com \
--cc=bass@buaa.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=yongsuyoo0215@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox