Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1477165rwj; Sun, 18 Dec 2022 08:58:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf5k55v+NYfPpm9gmEswKzprVl1hEHCoX1zj3bdtHcTnPqoiLRedGkK12CpO/cC2qPufQYh2 X-Received: by 2002:a05:6402:370a:b0:461:2505:832d with SMTP id ek10-20020a056402370a00b004612505832dmr45891733edb.10.1671382708435; Sun, 18 Dec 2022 08:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671382708; cv=none; d=google.com; s=arc-20160816; b=qitbjAIB0JuV8UXdJmmTCm0YkvALYmeJhKXxPQfSQmgh/rCUvPtnt7yw6FVkT6MOnT f4373M22kJVlDNcgeK2LerBJaCqlqKphbC8QwHk+x097kNXlSq+uVaQr1YwBh2Uuk6ya 638UvVtrgyKoRdAOj0Hm6a9W8sqKRmAvDL3oE5MCOI6RQ4E5iiLP4q1yNsV0ZmjlbHHx /0mwMdMJRdzw+TS/LUAzitlq4xr6uIN4xYhVmd1CZ8vOfKm+H5NrmLWggpY4ImEyY1e+ 0mWpJ4aHGMCBfIA0MQFQH7rCm9otrEAdcUHnjD8CZPlJQIIDxEIpzSOwns4NIDp8CltT DkUA== 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:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ci+7gLRRIFaHNNhOJlU5n51aNUtyCGeUdSdPqk2psMU=; b=eRpTlxNwhWo0jp1Xn2Du7vvfOK/jCAn52e/A+9XKsMMW7sDNL6zV9VGrwvKDmNbYfe 4CypYgouuRR7A9W9gEKgFIb2WPLVnGUvO/C34V2t6fxIYGHim/4pMjql/iJmu33Of50r WmwtwXlxDXE95uJ2KGjIj8G3CBuEo4kSJRDPpxwSM3KBajG0juw8BMupn+505lHS7IMh 9NmoPq2xr04V6JVTTvMDIK3Eeig1z3kMfE2Dd7sW1td2237stw1vPPHwI0QTC4arb3ut LrmbGYqnIhozDs8pqHNOGZCYrCZzhgniVJsbTWowDHpAJfOUDmo4z507SuOhJ/nXAhlr VoZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="NHi/1agd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a056402180c00b0046ba0b760dbsi5841688edy.466.2022.12.18.08.58.11; Sun, 18 Dec 2022 08:58:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="NHi/1agd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbiLRQpk (ORCPT + 70 others); Sun, 18 Dec 2022 11:45:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232645AbiLRQon (ORCPT ); Sun, 18 Dec 2022 11:44:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FE62BF53; Sun, 18 Dec 2022 08:15:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2FF98B803F1; Sun, 18 Dec 2022 16:15:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D96ADC433EF; Sun, 18 Dec 2022 16:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380151; bh=iTuO9QfbW5dOdxV+MuKHqJvpops+DbnddqpcwT5+1hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NHi/1agdqzvIkMrap9aUgpAlbuBl/9GxEFMLzu98mYr6y+xmF9UhJUnDCzofecsRO K4BCqnGh7m0c7s+Rt3GnBexT9dlMXqhLHO/mCCeSFahILKSZ0hAoTz4So3tgJXBBeX nJSalUSmmchBiGXpkP5mXrGOwCUW2DCjVEgawFNfRLlIa8voH69Ntp8XV3IAsNeseI KhG61bLlo40rDhnTjfLrvs3DjzDY71Tb0rVgvoVrsV/W65Rd5lY9ZrZUYmxVxNlL0W y0LntbNcMPNOCZqSM549S6v5/FKoi07fvsa2TeMtTBeQ6yK3Yl4Er4ig5dBgo0z0S2 x5JYlEM39iJow== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shigeru Yoshida , syzbot+9ca7a12fd736d93e0232@syzkaller.appspotmail.com, Hans Verkuil , Sasha Levin , hverkuil@xs4all.nl, mchehab@kernel.org, linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 45/46] media: si470x: Fix use-after-free in si470x_int_in_callback() Date: Sun, 18 Dec 2022 11:12:43 -0500 Message-Id: <20221218161244.930785-45-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shigeru Yoshida [ Upstream commit 7d21e0b1b41b21d628bf2afce777727bd4479aa5 ] syzbot reported use-after-free in si470x_int_in_callback() [1]. This indicates that urb->context, which contains struct si470x_device object, is freed when si470x_int_in_callback() is called. The cause of this issue is that si470x_int_in_callback() is called for freed urb. si470x_usb_driver_probe() calls si470x_start_usb(), which then calls usb_submit_urb() and si470x_start(). If si470x_start_usb() fails, si470x_usb_driver_probe() doesn't kill urb, but it just frees struct si470x_device object, as depicted below: si470x_usb_driver_probe() ... si470x_start_usb() ... usb_submit_urb() retval = si470x_start() return retval if (retval < 0) free struct si470x_device object, but don't kill urb This patch fixes this issue by killing urb when si470x_start_usb() fails and urb is submitted. If si470x_start_usb() fails and urb is not submitted, i.e. submitting usb fails, it just frees struct si470x_device object. Reported-by: syzbot+9ca7a12fd736d93e0232@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=94ed6dddd5a55e90fd4bab942aa4bb297741d977 [1] Signed-off-by: Shigeru Yoshida Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/media/radio/si470x/radio-si470x-usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c index 3f8634a46573..1365ae732b79 100644 --- a/drivers/media/radio/si470x/radio-si470x-usb.c +++ b/drivers/media/radio/si470x/radio-si470x-usb.c @@ -733,8 +733,10 @@ static int si470x_usb_driver_probe(struct usb_interface *intf, /* start radio */ retval = si470x_start_usb(radio); - if (retval < 0) + if (retval < 0 && !radio->int_in_running) goto err_buf; + else if (retval < 0) /* in case of radio->int_in_running == 1 */ + goto err_all; /* set initial frequency */ si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */ -- 2.35.1