From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410177; b=Aq1rKp7hq9+7uZYdboZJI+s2em5lSqGsEDGgexFewb/fJ8n5OPJZIeYLnEf0VR57SCC2 iGUGsmC/hCfXKLQjkKGIQiMJ3+AZSeEC/djuCDYfFpngi7xUfZIcW5bd6RV936oE/s4S+ JUv2I5MON+kaI4ifyJT1XZK958T7zglPNdjwqkfEOZwai/qK3Zkef3VAvCaAg1bRoPWXL zPTY4iI+37bkYnHXWaG2yEdKn1GGIgfYeSZCt1E8WGg5tSmeMo5Z+yWDcfuphbfjc7M1o PxDDdzFAo0CMTaDBrB8OaDXXU2RUywxxnIlJroIilU9ROz1OuvG+mcYxsOY5nzTSNFA== 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=TZsjB8Nnb8Dd6yS0hXEzIfVrPtmfMF5y9hqEib5HC7XpwWqXvb901cPCL9sdRe0KumcI ojsaPSDIY+FZqZutMBhvqrzXExzlyYn4gKWTZ0kjEhnvMTy9sEPxpr+ze1FrzYYoS7Hyd R3zMhFZ/4TPAMOtqBXvQObM26m0A3NaHB4sK8Urr+Vi8rei2B/g1VBu8WBCpMBNfEPbkJ leNE1AtvpnlYwbhGLRY+KE7SbD38UM7hpw1edxJcIbbq3fWIluhuVgaTVgAraZacx9RHx rOC+I8a/dGeOuXLulSQWX2iE0hyc73MkDggy9odDhX2it+/Nsm9RC1z8eH1PeI43B3Q== 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.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 311BD606A32C for ; Fri, 4 Dec 2026 18:49:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 311BD606A32C 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-f54.google.com with SMTP id a92af1059eb24-1b589050416so1521506c88.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=v0899M5c7NFEkuZpnOqNdU4M7O8X2opn+pZ35WlGUQnnx01UwgwIQq1NHTjaOdS9IC ECcQalbIUIoWxOSRl2voTLSQX5wAhEko3eCebUICVKJbIsqrHS+NKX3yJgXz/3YYmks1 d6sKRK2v5j+JHFsHKYQMQzwKFFyyslzRx/vBFdTNZY7O+23Bm1TEx6VwiCO+EZRqrsXW 6ealDZCAI6pnwrnyAxy64g7DJEuw0bE/nJVU6Ek4kAMEYMxz1bYgk5EhjaA/T9rQTnPD AP9WveG/rLfEJlIgqtuzNFtuaug0aC0C4Uxc4MH8hlQ6ouzZSCSFL2sbyS38EXXXGZDR Glfg== X-Forwarded-Encrypted: i=1; AL+hErHpWqpUC9eQxNuA306AvqJ15xKWiJatMxCC8d9SgadWKs4gwA5r4zlL5hZ6KK/smmB0cydQ+elxxVYBeZA=@vger.kernel.org X-Gm-Message-State: APuU4Z8pduhGrqrXH3OTvQ2+P0JZRNisUqOJfIyfPBmb99P8XcWitfLQ MbpDc64eFi7bqdMYuZCH/R6JBzKL6KBkJXzBMLkN8AAI3NX9ifU/7eto X-Gm-Gg: AZFdTZdAE55sU4dNLv9yVG+IItiEsJAnqk7NeMUBbcML4LvurHIeoAwtYNm4ktJz3qi VTiEX8Wne2Bmq+qvzf9xCcL2jFYqm1t+M7CvvMpOtzZSB+x5x0lv3bpyGHc7giLKsqIx+jwozuR rMTf7FNLOBbPEcLyNEPpcdfoRhgm6R5dEJEy1Oh0ZCYD4/3y2RVo6Q+uYstQ9NcLPRewX6Z88ZU fmrpN0WGeiy+Bwyxmv8Yvi+6yzxpV37qoa5xHmuH1skIxI+yKqB81rK9xdtP67Nt943ohPIkDxu HHsAIa6vjDaxMbssWUivmjNy/2ceheGhVZRl3wUUZ1vWAz0jNzMTrXKVlsTQpBACvU2WkQ8KjSf /VY6+4cDNyBl4Pl4vzW8I6s1hieQYR6VLe0XPxrVMzh9T66l16rbS5iwaMh0LCpcVQV9QBO2CGE AqmQ+fo/vz6B6xLubelk+oBh5uo9GOY1Ag5W8jUa/kgPECkLp+tD0gWgUgNSwkqqEYV+9WJ9J3+ KoEiBaiH5ec7UX1VVscrI1Os/lbjsE0+3De1YOmYmBzcb74DdQZX27In9uD5tTdhJkInovqfIKc zf1wYE9Epyutk/TMoinawLwbBSwmCVz5CQiMi5TmUgi+JD6MmDInbwT6vI2EqDkfk6Spb4B5/57 rp2/8IYFWsIGl 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-kernel@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