From patchwork Tue Oct 11 13:31:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1688663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=oHoj2KVV; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MmxXg1TSWz23jS for ; Wed, 12 Oct 2022 00:32:19 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oiFMh-00016G-9s; Tue, 11 Oct 2022 13:32:11 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oiFMe-00015w-Sz for kernel-team@lists.ubuntu.com; Tue, 11 Oct 2022 13:32:08 +0000 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 8D8653F127 for ; Tue, 11 Oct 2022 13:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1665495128; bh=ew4z0OWLzuJb3zSPXF8AzMY8B7LSqoPrg7HoIoTZt98=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oHoj2KVVuCaMIW4VkgaZlCtqyKa5YOa2ASEGh67KylR5Cdpjdfno/1TG0EHo4/BVi 5iYG1s36Uioy+gGb31etxx/GR1BtlCqJ2gFDKyCGxLd3+v1ZAoQxdyO/o9p7wmUkBs 4MFFWD4IBE2u3X9CnY5+ocF2ykrakHx3B8j6C+8L6jErMvc2oDBTRWRZruGjaoIy9U Mx57HhSflT36i4Lyt+t/RzsT+8GZn/zyUPcBfu/cAXxLAHdGUOGv28riC/mr6zTYq6 ijGKmZoP/sWeecfZDTmbh3/sPY3RWpF5rk0YC3EhAHUwgUZwOdPwYIH30aSKO+ziye 0ambWSyBOuRAQ== Received: by mail-ej1-f71.google.com with SMTP id sh33-20020a1709076ea100b0078d28567b70so5947845ejc.16 for ; Tue, 11 Oct 2022 06:32:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ew4z0OWLzuJb3zSPXF8AzMY8B7LSqoPrg7HoIoTZt98=; b=vAbIzpiORoeVqcsPhTNRcqgRZNDrTvYFJ7Ld2JI6Q2ss3fXDqjBIxvh1Aswyl63Fmf 8/G+am5oJ6qFW59Fb0U1bLw3cNzlUWvHLobrD6tYvpRLqye+GRStudG2Eyn1Sy46kj12 bcXo16NieiryGhd945HukJ5hk5FHGWZF7cYDxn80DSRHzw4QNb6lXqDklvhj4611aTBv YP9KM7P1vZ2M+yF0GY1YzUUlWtSbhUgiG5SQ8fvTBufuiSMbNpOoQH1wu+8WyjXeN5nR j/ofm7Mm4Tm5NBBTwdXFO6llZkrPhpGuwXiurcRfsjKeOJKpLDNWdynxIIvnzPM8JYrW lGIg== X-Gm-Message-State: ACrzQf31I5bvOUzJMaKB/ScKR7hjboqYShsfvB8kwcM5zsI1L3bbAsOP QS9j/hzpP8DIh+Ti/h7339TqbWZAFAoLvRpSJn0dVPPQfPuWcH+Pqt3v0gpbQ+xeMexWYyujpju ssCRbraFbcDaiq/uD1I7qDBufSY0SFKFV32EJvMXqbQ== X-Received: by 2002:a05:6402:f83:b0:458:8c97:29af with SMTP id eh3-20020a0564020f8300b004588c9729afmr22874673edb.210.1665495127989; Tue, 11 Oct 2022 06:32:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4AHkZekynz02ruwWYuk+oaMUX16Tw49UDnW8sMHGha40uld3KMqZGO463KnHftV67vQBiiMQ== X-Received: by 2002:a05:6402:f83:b0:458:8c97:29af with SMTP id eh3-20020a0564020f8300b004588c9729afmr22874655edb.210.1665495127766; Tue, 11 Oct 2022 06:32:07 -0700 (PDT) Received: from localhost ([2001:67c:1560:8007::aac:c03c]) by smtp.gmail.com with ESMTPSA id g7-20020a170906538700b0078d9cd0d2d6sm4896930ejo.11.2022.10.11.06.32.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 06:32:07 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Bionic 1/1] media: em28xx: initialize refcount before kref_get Date: Tue, 11 Oct 2022 16:31:33 +0300 Message-Id: <20221011133131.262529-2-cengiz.can@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011133131.262529-1-cengiz.can@canonical.com> References: <20221011133131.262529-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dongliang Mu commit c08eadca1bdfa099e20a32f8fa4b52b2f672236d upstream. The commit 47677e51e2a4("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") adds kref_get to many init functions (e.g., em28xx_audio_init). However, kref_init is called too late in em28xx_usb_probe, since em28xx_init_dev before will invoke those init functions and call kref_get function. Then refcount bug occurs in my local syzkaller instance. Fix it by moving kref_init before em28xx_init_dev. This issue occurs not only in dev but also dev->dev_next. Fixes: 47677e51e2a4 ("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") Reported-by: syzkaller Signed-off-by: Dongliang Mu Signed-off-by: Hans Verkuil [DP: drop changes related to dev->dev_next as second tuner functionality was added in 4.16] Signed-off-by: Dragos-Marian Panait Signed-off-by: Greg Kroah-Hartman CVE-2022-3239 (cherry picked from commit 1f6ab281f218c3a2b789eb976c5b1ef67139680a linux-4.14.y) Signed-off-by: Cengiz Can --- drivers/media/usb/em28xx/em28xx-cards.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c index b736c027a0bd0..23a9fe8d9d1ef 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -3644,6 +3644,8 @@ static int em28xx_usb_probe(struct usb_interface *interface, goto err_free; } + kref_init(&dev->ref); + dev->devno = nr; dev->model = id->driver_info; dev->alt = -1; @@ -3730,8 +3732,6 @@ static int em28xx_usb_probe(struct usb_interface *interface, dev->dvb_xfer_bulk ? "bulk" : "isoc"); } - kref_init(&dev->ref); - request_modules(dev); /*