Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp287509pxp; Wed, 16 Mar 2022 06:01:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGr//t6uOU5Re57BXh+dwEBNjCWTQgwAhWWhw9TXGk/VYdtLwSpw9RfJdU+KjksknHN8Yc X-Received: by 2002:a17:907:3e22:b0:6da:83fd:418 with SMTP id hp34-20020a1709073e2200b006da83fd0418mr27401483ejc.321.1647435681432; Wed, 16 Mar 2022 06:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647435681; cv=none; d=google.com; s=arc-20160816; b=dle1VTVQtibtoY2hbXkFkp7wDWc6OlErbXmxpFwPXNJH0J9Dj0UrSP5mTrvWM7DhG0 ps4xhTnwdktwWIFA9HyIPgZYqj6qeFJ1l1YcEpzQjk1V7JhzrYVczpU/oGgdyy/dv0Pd e6nrV+dxwE2TNPRlBSAnWj4r3Se/4iDlt8gKE9s9+eamwcrzkPszs7ZOK6eGl/uhaMoW rNwTbHHrkWihOkY93OWpzR6419FnO6yjth3Z76mLxf95d1yz4/TznCNeN+7OF1kGAq7d 1FrIjgcRMLK8a8KLRbJwC2eq7/TtgQZebr7YM9l2lXVi+GViXpKqOyhB53vcuiSeXeDO Lthw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fXY5SSc67OQ3Mv1EujMKdX7NuooW9DebYcBGol9Tlwk=; b=WBE8+NZGX1IFcTN9Zrw7qdHR3VLB/XHx1MDODQ2x3VnjtGXitkaKT+vML9PKcsGpzt oby9KGJWJDl90Bbdg/oRLiGWgBt0Pf3ZCYqvZiL2p92e9yIR2hU3RjJKOUW/i1Q/SP94 Igblz3J8nHYYIjLfvt3eSaOsrL6d0qtSNfDCf/WYKsGMbj6Mbr7MCok3h+ZDB8EbB1Vb +dNg3Kaa11VtxigQNc7DCF2AMwRjwlCFR76jN7IL0SHKDq+wmrXaywppeAQF56qgwleL 5ly848bG0NLFfeu32huRYkF3dDghNYGqvbiS+DWJkFUx7RnBLJmQLyxgG4ABDOqoAozj kwMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xzpyjiYJ; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a50cf05000000b00416a66c3f7dsi1302103edk.405.2022.03.16.06.00.37; Wed, 16 Mar 2022 06:01:21 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=xzpyjiYJ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239473AbiCNLmV (ORCPT + 99 others); Mon, 14 Mar 2022 07:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232165AbiCNLmG (ORCPT ); Mon, 14 Mar 2022 07:42:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 834A248303; Mon, 14 Mar 2022 04:39:36 -0700 (PDT) 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 ED289B80D96; Mon, 14 Mar 2022 11:39:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BFB6C340E9; Mon, 14 Mar 2022 11:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647257957; bh=KEam3vhPVA6p6R9OrQaWfRPkiJLYvrfBks84jOACUpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xzpyjiYJtfF5mMunRzNDtUpeesLxtUdG2PEZvMUW3p3lnJjCGFD43zsms5e4oOkO3 wXo27ceHwmLl0PH1S8HlaNNQpFc7vcOBNoUxvBoxkEDd08y/2/NV6wo/98qb1thjI5 SCWejIaUhODFP75eefa2B/Ogzb2goF2Ql73pkvhk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Krzysztof Kozlowski , Jakub Kicinski , Sasha Levin , syzbot+16bcb127fb73baeecb14@syzkaller.appspotmail.com Subject: [PATCH 4.19 08/30] NFC: port100: fix use-after-free in port100_send_complete Date: Mon, 14 Mar 2022 12:34:26 +0100 Message-Id: <20220314112732.023900342@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112731.785042288@linuxfoundation.org> References: <20220314112731.785042288@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 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,T_SCC_BODY_TEXT_LINE 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: Pavel Skripkin [ Upstream commit f80cfe2f26581f188429c12bd937eb905ad3ac7b ] Syzbot reported UAF in port100_send_complete(). The root case is in missing usb_kill_urb() calls on error handling path of ->probe function. port100_send_complete() accesses devm allocated memory which will be freed on probe failure. We should kill this urbs before returning an error from probe function to prevent reported use-after-free Fail log: BUG: KASAN: use-after-free in port100_send_complete+0x16e/0x1a0 drivers/nfc/port100.c:935 Read of size 1 at addr ffff88801bb59540 by task ksoftirqd/2/26 ... Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 print_address_description.constprop.0.cold+0x8d/0x303 mm/kasan/report.c:255 __kasan_report mm/kasan/report.c:442 [inline] kasan_report.cold+0x83/0xdf mm/kasan/report.c:459 port100_send_complete+0x16e/0x1a0 drivers/nfc/port100.c:935 __usb_hcd_giveback_urb+0x2b0/0x5c0 drivers/usb/core/hcd.c:1670 ... Allocated by task 1255: kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38 kasan_set_track mm/kasan/common.c:45 [inline] set_alloc_info mm/kasan/common.c:436 [inline] ____kasan_kmalloc mm/kasan/common.c:515 [inline] ____kasan_kmalloc mm/kasan/common.c:474 [inline] __kasan_kmalloc+0xa6/0xd0 mm/kasan/common.c:524 alloc_dr drivers/base/devres.c:116 [inline] devm_kmalloc+0x96/0x1d0 drivers/base/devres.c:823 devm_kzalloc include/linux/device.h:209 [inline] port100_probe+0x8a/0x1320 drivers/nfc/port100.c:1502 Freed by task 1255: kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38 kasan_set_track+0x21/0x30 mm/kasan/common.c:45 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370 ____kasan_slab_free mm/kasan/common.c:366 [inline] ____kasan_slab_free+0xff/0x140 mm/kasan/common.c:328 kasan_slab_free include/linux/kasan.h:236 [inline] __cache_free mm/slab.c:3437 [inline] kfree+0xf8/0x2b0 mm/slab.c:3794 release_nodes+0x112/0x1a0 drivers/base/devres.c:501 devres_release_all+0x114/0x190 drivers/base/devres.c:530 really_probe+0x626/0xcc0 drivers/base/dd.c:670 Reported-and-tested-by: syzbot+16bcb127fb73baeecb14@syzkaller.appspotmail.com Fixes: 0347a6ab300a ("NFC: port100: Commands mechanism implementation") Signed-off-by: Pavel Skripkin Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20220308185007.6987-1-paskripkin@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/nfc/port100.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c index 0f37acec98ab..bc680b8be133 100644 --- a/drivers/nfc/port100.c +++ b/drivers/nfc/port100.c @@ -1618,7 +1618,9 @@ static int port100_probe(struct usb_interface *interface, nfc_digital_free_device(dev->nfc_digital_dev); error: + usb_kill_urb(dev->in_urb); usb_free_urb(dev->in_urb); + usb_kill_urb(dev->out_urb); usb_free_urb(dev->out_urb); usb_put_dev(dev->udev); -- 2.34.1