Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2238391rdg; Sun, 15 Oct 2023 18:55:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxm1mPftyaU8bKcxIxOtIyIOHBDqVnrevgIVcP9iC9MfevYJ/FlpKCOh38/XbUhbdVd1dZ X-Received: by 2002:a05:6808:91a:b0:3a7:4987:d44 with SMTP id w26-20020a056808091a00b003a749870d44mr34409014oih.20.1697421322684; Sun, 15 Oct 2023 18:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697421322; cv=none; d=google.com; s=arc-20160816; b=uYauSiUTuUlIikuw5Yw1/zX1U9YkPin6+hipubsKvnoG9Rqwv15lIN7e3Viu1nretk sHRpVp8q0jT0T8bjuUvrhhc32HTEGl40NYh4qnGvfe1u9gnSJ8Z6w0LSlzJxbo/b2Q/q gId/xtN7H87/12Et4RbPE8Rujs0ip5uWdzX5lKFixmJ7vsBzQ6ZSv0C9A7Z0ZK4p83rj Fsh16UqTJS9dQpiOySp/DLfM7XSdq0wAW0advpbdaDomY+pA+I6VuB5Qja5fHrLkg/I0 mCAaNlnytx8JEs84NuGnUK15ZvrFCk4l7ipNkbZcB58LpZKroyusRrsM+LgA4RxBEI0N ZHpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:message-id:in-reply-to:subject:cc:to:from:date :original-cc:author:original-subject:dkim-signature; bh=kS0RTd3CYTDBCJcqdUFcBC+zypJLcH4lZRAhcLFcZb8=; fh=hhl+Xxf3QNvgt9rFL6FnWz5gRc0nTpeNg4u6SEAaZpc=; b=pGxVz85a3LNIvFe9BtIemNeiOTUlABZE/RTwqOSM78OILShSp8BCeUYsPDuCvpAgBB XO/QIwrs50vxoin9KPMz1fVpmdtKzs2RD55HYLFK0eSdfEt4AZOrQr9ei3z0xiebQDrQ s3CTQCoTmm1FF49lyZSkN7TbFK4P7cv8tnW603/+BxVHMtHPtxxxj3WZdcjoXEW1W2uR 0fpPp2PCj5I4JYC6kBV/9CjQ3AahtI0oNgEsIap3JTfNiE2RYuq7zUIL5YPfzIIY0PJn QkTGpEs77wyLtNjoBqwE+zQfUJbmlSYti7YUfP4yNu2OusexAMezBWYz27Qz4dJ8AOvC 6GAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isely.net header.s=deb header.b=BU2P7bfw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00573f786103dsi9488864pgb.754.2023.10.15.18.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 18:55:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@isely.net header.s=deb header.b=BU2P7bfw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4B4AE805C3FD; Sun, 15 Oct 2023 18:55:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbjJPBzM (ORCPT + 99 others); Sun, 15 Oct 2023 21:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230497AbjJPBzL (ORCPT ); Sun, 15 Oct 2023 21:55:11 -0400 X-Greylist: delayed 310 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 15 Oct 2023 18:55:08 PDT Received: from cnc.isely.net (cnc.isely.net [192.69.181.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B124AA9; Sun, 15 Oct 2023 18:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isely.net; s=deb; t=1697420997; bh=kS0RTd3CYTDBCJcqdUFcBC+zypJLcH4lZRAhcLFcZb8=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=BU2P7bfwss2/P+6aqWSIk9NJvJoB13SWtKIlBfGLT7svcwvSlZDnlIJUXIhcYjjUb b2yTdAX8rOy6iZa101JPW+Bc+nwQbYEQKFp3f9+9B49/hOZ2SbHpO7cpq1+gWKSUJb Rk7iL1Zq3+Cn2TaFXegiEyyVUkaKHoyDguYGqL/XaVeVnjnJupWJ7O9/dgH6O Original-Subject: Re: [PATCH] media: pvrusb2: fix use after free on context disconnection Author: Mike Isely Original-cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, Linux Kernel Mailing List , syzbot+621409285c4156a009b3@syzkaller.appspotmail.com, linux-kernel-mentees@lists.linuxfoundation.org Received: from sheridan.isely.net (sheridan.isely.net [::ffff:192.168.24.5]) (AUTH: PLAIN isely, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by cnc.isely.net with ESMTPSA id 0000000000080091.00000000652C96C5.00000BA0; Sun, 15 Oct 2023 20:49:57 -0500 Date: Sun, 15 Oct 2023 20:49:57 -0500 (CDT) From: Mike Isely To: "Ricardo B. Marliere" cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, Linux Kernel Mailing List , syzbot+621409285c4156a009b3@syzkaller.appspotmail.com, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [PATCH] media: pvrusb2: fix use after free on context disconnection In-Reply-To: <20231012230911.48113-2-ricardo@marliere.net> Message-ID: <5f652494-1e4f-4965-f9b7-0f2bf05f718f@isely.net> References: <20231012230911.48113-2-ricardo@marliere.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 15 Oct 2023 18:55:20 -0700 (PDT) Acked-by: Mike Isely -Mike On Thu, 12 Oct 2023, Ricardo B. Marliere wrote: > Upon module load, a kthread is created targeting the > pvr2_context_thread_func function, which may call pvr2_context_destroy > and thus call kfree() on the context object. However, that might happen > before the usb hub_event handler is able to notify the driver. This > patch adds a sanity check before the invalid read reported by syzbot, > within the context disconnection call stack. > > Fixes: e5be15c63804 ("V4L/DVB (7711): pvrusb2: Fix race on module unload") > Reported-and-tested-by: syzbot+621409285c4156a009b3@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/all/000000000000a02a4205fff8eb92@google.com/ > Signed-off-by: Ricardo B. Marliere > --- > drivers/media/usb/pvrusb2/pvrusb2-context.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/usb/pvrusb2/pvrusb2-context.c b/drivers/media/usb/pvrusb2/pvrusb2-context.c > index 14170a5d72b3..1764674de98b 100644 > --- a/drivers/media/usb/pvrusb2/pvrusb2-context.c > +++ b/drivers/media/usb/pvrusb2/pvrusb2-context.c > @@ -268,7 +268,8 @@ void pvr2_context_disconnect(struct pvr2_context *mp) > { > pvr2_hdw_disconnect(mp->hdw); > mp->disconnect_flag = !0; > - pvr2_context_notify(mp); > + if (!pvr2_context_shutok()) > + pvr2_context_notify(mp); > } > > >