Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3042023pxp; Mon, 14 Mar 2022 09:39:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmFHD+x33aAAzyRYPVOFJv1vhZx5uneTFj4BFtAo1uJatLi0Lx5ttvzEBxyzqw6v39UNN9 X-Received: by 2002:a17:90b:4d82:b0:1c5:d65:9a3a with SMTP id oj2-20020a17090b4d8200b001c50d659a3amr109779pjb.112.1647275955652; Mon, 14 Mar 2022 09:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647275955; cv=none; d=google.com; s=arc-20160816; b=LdD1GxKvRfAeCljgGzGrK54+l+uTE1mNwCYhoQ5Hs7e6F6pUHJ6kWZmSY1PWRdcK77 IKusBD1/PH/TwBFpmbKh1VSQFo2oD30Y76+2Aqw6K9qU2/c2xhPJViqjIyXNX6NXywYp Gy7KG9Bqy2QisnZi/bFxF8w0WqDn4lIVq0Vp9vfJUT0zZxzN55QV3+5lMtCo8J3mOaaR 4PUm2ky5gpSCYSoPRiWcteDCV4HKP95S3I8WtzSV0xoXpA1j+FBkRyLQMIkqDnwrgVUb bI09cUOzjvvnmKpuAlGBd0RdQ0ncUWXcZTNQKbjPTY09hTYzWl8mJ96S3CJTCY/2a/v3 tsCw== 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=vGIjwO8HPdOrcVlkJ9+IgWORLKMWzlMQ8b+pCU0jtgk=; b=FA0bxlHb50P5qLUtv2PJgSIHONAPZQK5zR9kt2UP15DoT2Axnk3m5w3fAV44RNbqy/ 5IKjdSqzZGIrRzHiAJ3iPip07lOh7yUtiVjuvaWWvrHZnoykUHTXHBg29683hxksM7kT 8vAb+xfDr80cEAtqu8y2UfbD5rLmKvugzVsZpD/2Z2Cqck6vpFd1iH+pe6b9JhRu9Sco gc1CKwI/SK+tzXoJF4qmuyJZzPRFfLaQc3cTtxSXC3R+3PuPcDVaA9MsgonhBoAglrhP 1pVr6/xbf3GHYFBD6fnS6kW20NdauYMi8/1I9vDJ4bUcIJOOpx1CEh1vSI73U+2Y0/sL vnUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zAScQ5yj; 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 8-20020a056a00070800b004ca9f0a3a29si8962279pfl.267.2022.03.14.09.39.02; Mon, 14 Mar 2022 09:39:15 -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=zAScQ5yj; 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 S241639AbiCNM0q (ORCPT + 99 others); Mon, 14 Mar 2022 08:26:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242759AbiCNMTi (ORCPT ); Mon, 14 Mar 2022 08:19:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2C43C72F; Mon, 14 Mar 2022 05:14:42 -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 54A81B80DEB; Mon, 14 Mar 2022 12:14:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE1A9C340E9; Mon, 14 Mar 2022 12:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260079; bh=o1qmkW3ZoAZBrUFAtR437fZ26gI3ph1x0mg6GeiVfAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zAScQ5yjNmBaUK+zOAkWDtZBHeI6+p5p9c/jjqOoe/gcthY38xpxpj0pmvbWPy/2u IHNUkADb6t0ZVZh5K3thV5B3+mtHvl8WiX05Jf7lYF9UZh/giQYxfbD9ilRJ8v6Ntt 5Q43DuNRhf+9D/u6T1Kj0e8N7aTBD8w1wIvGnrn0= 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 5.16 049/121] NFC: port100: fix use-after-free in port100_send_complete Date: Mon, 14 Mar 2022 12:53:52 +0100 Message-Id: <20220314112745.495119683@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@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 d7db1a0e6be1..00d8ea6dcb5d 100644 --- a/drivers/nfc/port100.c +++ b/drivers/nfc/port100.c @@ -1612,7 +1612,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