From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410177; b=nELKAb+rO+IdBvXjscDAURsc1AwEQ4y1o6ddtJ8dJfAImP5I+pJ7GM9LBGrll2ecpMS/ N58nLd8rNy8EDtqLxkmi+v4ECwLxtYtkdH/FMwdWyKvqP9DnIFlqwlQLfLngLKFzJ+o1/ xIfZRiobpKV36lRg6scZo/srtZyooF0EBvdJriUdOAoDCqI+98xqTmm4j7h/Iu3HpqPs0 1ryPR78X9m+zsssZgmnJdL7jhsEE9VzwXVZT6HWVVI5pTnuy5yCUblv7EeVVdDWJl0qu1 v8x/QyD8ZrrWjtZZsn3is7BBe6Xs5AM6B8kUC9pwGiMjmKvdyoX+Gh7WfHWF48Wq/Bw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410177; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=aJUsjHpdpfL8mxo3PYZ1c0QxbqiLpHlZkR6oa58gS14=; b=mHThsUKyyuBbq3FJ/FdTiI+3Hz9EGBTI4/CNZZwUPhqw/cHs8hG1F7YNDpUmk8KXIrwQ 1eA5ubyB4JB51xG8rkrgHWyha7MyxPn3mi9zAVMcS3SXDDq4q6dAye+bCkfOAub55Yg8c MlgqNFHCqWNNIcLwW8YCBV//qxoE5or3km0T+9UldiHn/slDsisFlOORaktdTSjR8nq2T fTEvFxgj9tAHj34DUFsYlnDfjRInJsAWGuTvX23wmaQ2MnmiD/sBO9DIRpKJ6RKvivS3W 9D5Wq310RpUvvX2JJ3HlmTHsjMv5TkFxGOxVtdQDRIWk+MG5PmPeMcES2X16zKv2Lsg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dTOLFsg+; arc=none smtp.remote-ip=74.125.82.52 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34234606A32F for ; Fri, 4 Dec 2026 18:49:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34234606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dTOLFsg+ Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1b589050416so1521505c88.0 for ; Fri, 04 Dec 2026 10:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410175; x=1797014975; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=aJUsjHpdpfL8mxo3PYZ1c0QxbqiLpHlZkR6oa58gS14=; b=dTOLFsg+z1BvdhZ82ShGn4rmTNhzUSAgXrxXeSCCdn/R0z1mWxD6VJkz73aAjUfxAE KjY9ws0aZaRp4rma/o6G/MTufXqHPxBs8KnJ08OXjAiaWaCIa6nthJx5WSC/mt2kdXL2 KlGcEwxL+KU2QUMUpOllt9SZv3OZ3LRlX0SlvyISsnNDuphE9YcTpEPka8ZUsUhGbDrA Qavq2KdEa2p89z4YbfldpJeAkkvOkOEYLdsxgd0FshuRfvadjDFlACXHKVUARuy6x3pX mfwsmoYTPNX1KG/m6anBM+Sl5VAC7RzPaLOUaH3BwIIZS32oU5JvxYn7x24QT2M6rD1e 4nBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410175; x=1797014975; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aJUsjHpdpfL8mxo3PYZ1c0QxbqiLpHlZkR6oa58gS14=; b=qxA7b4yObSkabeu7mJugQyv3sRC5Lm9zKfTvqighvh7j3NBuQutDRwJeNKohtQQC+H Z6efgl/VHK/ujMjep4cEBN4YUAV4Gh9c0ldtScb9uGBMlFEA+9tF9RUlJkrJlLrsJfgb H+ERkE6DwOTd3mpW2ANbzfFExbiMVv1pkO72fmCnCBvcVl6P/iz8dKAIqpa7esAk/92h Wngvmxbn7zNooXFl2jR0M3ofLq7Hjh8lWsG48a1gF3eDom9mSXzjO1gtC09nrN3bR2rP lf0xhMoSQTqo+g5DvePYYCxXFD2mi4sKRjAthFyPVo3IEoS4m6hHREz7ET/TzCpr8Eg3 L/PA== X-Forwarded-Encrypted: i=1; AL+hErErE4bj5qBGLv13tYztUwSBGkq1cKD1ABSQkM+ZVlFyAmwjutapznJkr8Ol/8FargPYQTnZmzo=@vger.kernel.org X-Gm-Message-State: APuU4Z8KLyMffIrgfE95N3nu4beoLse1+0ypgMQOr4zKwI+nUTBA0MW3 vM/q5N0sVgjfHJhB4lfGhXhlO/aYCzQ51V+up5CcMzZ1l8ipj2fBXO9V X-Gm-Gg: AZFdTZecY8sABAsaoFRrRC1OJZNt5Pqnpm0NnqW6LlkFVM0k+wgzsmmTSJtj0NnbFbI azHzkeqQmP0K5HdvAlzytLRtAEQRjOeiuwhC6Pfx8aBvzeSoACnMs/t7rI+zaGKSK9oPilV+9Ti owKPg3WfEUQ7mjzuliRYtCVOpaB1ocjvnIrH6o/HyyBidgjnVc8tNRjlr0TL1AMlKgJBVl6vxiH OibqPmMz5TwScmVszYojfMsdgFNp19As5WoETnfWegCTVdN+NPzE9Rib1oXxcITvN3IZDIP6TMR 5WBTTgcBVZsYTP0i692C/tvB231KapRM3nCsgHhYcjqWRv8amDO1lc7QCkVMoVc49hrFmPwC5wE isuW8SCUHUAZjCUIZNSj2PdtleJqNSHERoG3HuW4ccsdtFjpXFMC1MN72Q5jKCFNJFxBSDO15mM jxk4tzPII1pHFz/oZFROrmUZDrrudEdtSVsBbEupP7d2p9c2nQmOJQQzxGllxm47N7HZO4rrDir duZV7UZXZJZcawq6dZcLtyib2uSAXw1GxsE8WKAqNXthJbwUCC031VALHmx6Iqf7DF82pBq7Ere ICHtpeRq8ITg6N9dEd8sYNsM9CoGMZ3lHLcV+BKOWTKBLRq5dgxRbhgxEJV8PIBedmLk6ZDbwHr zVeex2NcDehGI X-Received: by 2002:a05:701b:428e:20b0:1b3:755a:ec49 with SMTP id a92af1059eb24-1b5d71240ecmr2403103c88.40.1796410175317; Fri, 04 Dec 2026 10:49:35 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6455949sm9217019c88.9.2026.12.04.10.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:49:35 -0800 (PST) From: Praneeth Balasubramanian To: Mauro Carvalho Chehab , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [PATCH] media: bttv: Let the V4L2 core serialize the ioctls with btv->lock Date: Fri, 4 Dec 2026 10:49:28 -0800 Message-Id: <20261204184928.1686871-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit set_tvnorm() and set_input() must be called with btv->lock held, as their comments say, but bttv_s_std() and bttv_s_input() call them without it. Commit 587f0d5d6d44 ("[media] bttv: fix mutex use before init (BZ#24602)") removed the driver's own locking from the ioctl handlers, saying that the V4L2 core would serialize all ioctls from then on, but it never set video_device->lock. Only the buffer queue uses btv->lock (as q->lock since the vb2 conversion), so the core takes no lock for VIDIOC_S_STD, VIDIOC_S_INPUT and the other ioctls that do not touch the queue. Two such calls can therefore run at the same time and leave btv->tvnorm, btv->input, the cropping state, the timing registers and the subdevice routing out of sync, for example with the chip programmed for one standard while the driver reports another. Set vfd->lock to btv->lock for the video, vbi and radio devices, so the V4L2 core serializes all ioctls as intended. bttv_try_fmt_vbi_cap() and bttv_s_fmt_vbi_cap() took btv->lock themselves; drop that, since the core now holds it when they run. The missing lock was found by a static check that turns the locking rule in a function's comment into a Clang context-analysis requirement on its callers. Fixes: 587f0d5d6d44 ("[media] bttv: fix mutex use before init (BZ#24602)") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by a compiler-based check, part of research at UCSB SecLab. The locking rule stated in the kernel-doc comment of the called function was turned into a Clang context-analysis requirement (__must_hold) on that function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every caller. An LLM was used only to turn the comment into a machine-readable rule; the report itself comes from the compiler. The patch and changelog were drafted with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64, clang 23, allmodconfig). Not runtime-tested; I do not have this hardware, and I have not observed the race myself. drivers/media/pci/bt8xx/bttv-driver.c | 1 + drivers/media/pci/bt8xx/bttv-vbi.c | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c index 8b9ca59f9434..a9d5487cd5f7 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -3078,6 +3078,7 @@ static int vdev_init(struct bttv *btv, struct video_device *vfd, struct vb2_queue *q; *vfd = *template; vfd->v4l2_dev = &btv->c.v4l2_dev; + vfd->lock = &btv->lock; vfd->release = video_device_release_empty; video_set_drvdata(vfd, btv); snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", diff --git a/drivers/media/pci/bt8xx/bttv-vbi.c b/drivers/media/pci/bt8xx/bttv-vbi.c index 0ca88a2400ee..c2ceda4a15a9 100644 --- a/drivers/media/pci/bt8xx/bttv-vbi.c +++ b/drivers/media/pci/bt8xx/bttv-vbi.c @@ -247,13 +247,9 @@ int bttv_try_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt) const struct bttv_tvnorm *tvnorm; __s32 crop_start; - mutex_lock(&btv->lock); - tvnorm = &bttv_tvnorms[btv->tvnorm]; crop_start = btv->crop_start; - mutex_unlock(&btv->lock); - return try_fmt(&frt->fmt.vbi, tvnorm, crop_start); } @@ -265,8 +261,6 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt) __s32 start1, end; int rc; - mutex_lock(&btv->lock); - rc = -EBUSY; if (btv->resources & RESOURCE_VBI) goto fail; @@ -295,8 +289,6 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt) rc = 0; fail: - mutex_unlock(&btv->lock); - return rc; } -- 2.25.1