From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410176; b=EqmJr5jwatU6cW9KOYX248qAJA3nj/J+PEZN8KRFmX/JZ989eZBc9ylYaibtW745U/wj VsQH8Fvz6ZwEyuAnil2yfsMz/0j/7AMTNvSicCzya7fQfVm/wF2W6UHBKm7mtp2/016kS 2XgiWjIKd8+r3691sUnSdl0gfY4TK0gKA2PZ7EgFirGM7pD3oqhaxYlgdXwIiXdPSxjAW HoagEB//Ek6lzwBEk6JVE68SAFVoq90p1fJNYNk9/B4Pd29ViG1dV4ckJ4wI3cAhWfrqT O43cwQrNqk1Vj3CsmfJBt3gzj+tF8a3J00Iw+VRWgFmVhh+5hgvGQL3QpRxprrdIedA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410176; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=3ynGW6zwWKWQAqhBni9N+w8tqhDLFLP0OzNPQ0ocRXf8PHIa1nQwkDi8gsSMyCMlluQk eTAMVIEvl0+vzEH/f7f7y4ZMfwrlzYaPrCCuk0WYdSQVUzGKaXcGFISn5JjszFhlfhoGM NEdVmQj7/Vj+NiHeJ0fuhrCpdzlSZe+WJOEJlgtP53Frd+anV/zMv+axFHBRmqJjNuVX/ saHDmYX8WAgVrtNKj9p5NPXvwNDLHXppzDjHX+7F+ITTX1IGVO5yF5LZMpk1Nu44N04MO wHZiUg5XBeGJuLQHXGQeDL5yASfsdkEuUX5ql5j4cBFUdIwModh8NLr7Jm/vSTXMkeA== 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.44 Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (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 31EB8606A32D for ; Fri, 4 Dec 2026 18:49:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 31EB8606A32D 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-f44.google.com with SMTP id a92af1059eb24-1b59dfe466bso1908416c88.1 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=2wau+tBzjWFQaEsoypHqkqeTUQHWNMdYEdIZ0K1sjJ5hiVUyCRiDeB5eqyLROw7EUO lMNtjprcKdwrYbWmRhLpxUnv4cdqunSybC7KgXZm4PFi4wE3XaIJbdahf/RB5wJT9vG5 ISH/UDmexQTj8P4assynl9v/mCmpkA45urjRtlEStBesw5x1Sj4Yp1J9mpSaanhQ1Rl4 K4BlpeQud3SXCYtWnwteaOTntTeTXMjbHtwP8o8RXqK6oRcoSJxDlEq74xqjTvJZ4UYZ joibdrcdjgM6b5x4m/J7KjnCKlB9Tc0JvqU9ZaW5N3IWNC9ggP9YLhzkpkP0NhsXWAML SaHA== X-Gm-Message-State: APuU4Z8eUnvT6n9k5vtJaow8kpwX6eh6/ufvo9ZRyK6MlcLDSAHzVv5u xietUKP8HxmieFRQqUXV6A47mgC2BZg6uyx24OKZBOIyGntBloNwKH9t X-Gm-Gg: AZFdTZeKkDfRBKwfz0iErUAWLIRMr0u9piHrMhBcTbbBJVnbvrtYM/ZnBfdyTYVLQ/Z MFw2wM9ZPCd21ACVc7QjOSS+pgRVrXfwHYbKW+TsWkTWsp0ZXDHmkP9pFMXS9rHohIZaEzNcRlH mZMffA1VjZPD8+ztFfMcVows9rn301HqL9jxqYJ8JDKpZ9JARif9KmRaAUkKY2VrelVJ4xZdciy hm8DdI/b9BlxbFYNLSHui9KfUiXrx9ENANCxxgKb4Sr93BZSFSoUGCpnVVk51V6ytXxJruJ3MiF 7VmgX+TS9ZG+OsYb3IQkWwy4Rg9ZToMgqQqJJqjI1g5pFstAAwbQC80o+7dclLLiUAST57SjsWk XmRO/NXi5heezIwANxbNWzQMspVS8Abs0FK+9rqTOcOJBq9bCqm/1rkEMd3Cy1eXm+5Mji5f/he aDNFSpLYOAwkSXu6bErGR7ZwJ3wVJVYi9cTggAL4kFTEiYjlC9Q8Kq/p/1eQuIx+H7BJWGBXH8E hwLl0QoUXeRa4OFFnXI616/xms0OECuyubrr/OyiU3GJMZFmMOxkQKvY94HwwZ6NSHcSZWGmwk3 Bc8EHBbbC2VKLooo4UiFxSQ8/UErEClicgM4/yTOg2ZRhSxMEqpgcIDZNYQPesrggMKNN+2YS/N UM90ciFMAi+Ul 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: linux-media@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