From: Tuo Li <islituo@gmail.com>
To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl
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: bt8xx: Fix a possible data race in buffer_queue()
Date: Wed, 28 Jun 2023 15:19:51 +0800 [thread overview]
Message-ID: <20230628071951.1011421-1-islituo@gmail.com> (raw)
The variable btv->loop_irq is often protected by the lock btv->s_lock when
is accessed. Here is an example in bttv_irq_timeout():
spin_lock_irqsave(&btv->s_lock,flags);
...
btv->loop_irq = 0;
...
spin_unlock_irqrestore(&btv->s_lock,flags);
However, it is accessed without holding the lock btv->s_lock in
buffer_queue():
btv->loop_irq |= 1;
And thus a data race can occur.
To fix this possible data race, a lock and unlock pair is added when
accessing the variable btv->loop_irq in buffer_queue().
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/media/pci/bt8xx/bttv-driver.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 734f02b91aa3..241c51951627 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -1617,13 +1617,16 @@ buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
struct bttv_fh *fh = q->priv_data;
struct bttv *btv = fh->btv;
+ unsigned long flags;
+ spin_lock_irqsave(&btv->s_lock,flags);
buf->vb.state = VIDEOBUF_QUEUED;
list_add_tail(&buf->vb.queue,&btv->capture);
if (!btv->curr.frame_irq) {
btv->loop_irq |= 1;
bttv_set_dma(btv, 0x03);
}
+ spin_unlock_irqrestore(&btv->s_lock,flags);
}
static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
--
2.34.1
next reply other threads:[~2023-06-28 8:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 7:19 Tuo Li [this message]
2023-07-03 12:36 ` [PATCH] media: bt8xx: Fix a possible data race in buffer_queue() Deborah Brouwer
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=20230628071951.1011421-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=baijiaju1990@outlook.com \
--cc=bass@buaa.edu.cn \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
/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