Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp563358pxp; Wed, 9 Mar 2022 08:14:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlWEqxaG2QzkG7dtOd/t7u+rwbqDyWTQPNvPKTvIAFjyyWu7MNWmdsTYaMtK8fSYRVDMBH X-Received: by 2002:a50:d903:0:b0:416:17b1:8557 with SMTP id t3-20020a50d903000000b0041617b18557mr180603edj.372.1646842471490; Wed, 09 Mar 2022 08:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646842471; cv=none; d=google.com; s=arc-20160816; b=R3oYpwRPIe8/vnAEsppIg7GQi4rtxwoe6MxOOHZgclvtvS13+8iq7kVrg4mHNUP7Hk EjTkHFiiF1D6HZa2DW1n0wCbOM/DC1QcXPD2DGlK0Vnn/C/ZlfUTWEJndmG3085QB3Sx pAUNgCdp3htwxN8MhU43Y+lTLvq1LWF++aCiW3/TTP+HS134ns2MhEWaSD4hyJFsHjP0 Bb7Cw3nqJyLFg7+6sK/XZLShTBEHY2hPQ7hgOon6gaClGJhpThuQ6AU3vpDF8GEyTX2r xvSNoG4mOxzvlu/IaptHWetWo6wcwwVN9r1KHlIdau1vYdpdVwFAuTPviqiP8VOYdswn k1sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=U75FRdLGbZ3F+BR5tg2Db57c8QbYtEzo66rlGoHxRKA=; b=Ex+cBvKkIf/tnSTn9wUkBkrc993yXpc1sF7S8cIRrrS93u+2M+aIPJx64OWk1nowO1 bDJTy2uQGqpcdE2QdUY9EM4krhFPuDwN4PUmPdOuZnc4IXu0IyNoyMzlreFKKBDM2hA2 Fx+91C9/xmiIgHTjjoaDCtDWuUs0b11H9RL/ZrkHdGj7k57rOTJUAewPsJTj9BTv16cy dkxUA8ZNz7v8ZvU9+jwMjRzm97cJb/KsZc0Y0ZaLKnFLkTRQo8v9jXW/mcJGlFs1h1te STNcKxgfYrGvU/EQRBd4TO+zP9UCk+ZTAxIQYvJCcrtZ1iQk+t1QYoMTcFjsUlvBulU7 +Bwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=gTKaCzf8; 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=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id op2-20020a170906bce200b006db0cf32286si1237489ejb.901.2022.03.09.08.14.08; Wed, 09 Mar 2022 08:14:31 -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=@canonical.com header.s=20210705 header.b=gTKaCzf8; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232315AbiCIJxO (ORCPT + 99 others); Wed, 9 Mar 2022 04:53:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbiCIJxN (ORCPT ); Wed, 9 Mar 2022 04:53:13 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA40E16F970 for ; Wed, 9 Mar 2022 01:52:14 -0800 (PST) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 4401B3F07E for ; Wed, 9 Mar 2022 09:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646819533; bh=U75FRdLGbZ3F+BR5tg2Db57c8QbYtEzo66rlGoHxRKA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gTKaCzf8axqkYnK61BsdDpcMM28luPO81aTRtsHy0UP6f4Fh3Lo3ScP2s8IYE97WQ 8so6JQkTsoDu7dPLT7Of/pvHOOLs0mklZZtnAJ2o5QJxIzLewHS+ldCKMg+dCWgeU0 qeHLy2KV3HjiPDeefCqzcr3BE319IOW3+/VFqfHBgIxK4APjPNOPavkPdODcs6mh5+ 3mTgislXzrXoccWMvb8RhPAGI41n3aF3e1jLhdtv9wkNP1mOVP5w7kA+GkL0oKdu9W XlBm9yKVD01v0Gna44udhglojdjh+KB6KhQg/I1DI7CAgor2sBVBjaHzhgpjs5VdxV 2VVLbRC7uVVuQ== Received: by mail-ej1-f69.google.com with SMTP id jy20-20020a170907763400b006db62b6f4e0so1008334ejc.11 for ; Wed, 09 Mar 2022 01:52:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=U75FRdLGbZ3F+BR5tg2Db57c8QbYtEzo66rlGoHxRKA=; b=amHOWOY1+NhiRsbZ4yYpS8rSsUlLl6IvbyJMN3mMatE60IqLeJIU2gwMvxYrNrGyNQ id3AkuB6nfpBvLnc6EXRXMbe0J6PKr9egQuUCif8vmK9wjdc9R8PNV/FdREtKX/BChN4 GzxL0iPwbGoJOa+LaEQjmfUtpTaM0qSsHg+tIPmgvRnbXkQRvX5RX8WN4s+gS2TxNmnN INJ/fcWs2QhkjFxyrqfbAbO3pTAm6oNUC9jbgtvoNTQXJjLYSFDKDENqsZrAcNqpWFL/ 9KnFbqUcsmDwlc/rSazHCqgU6WEBGj+6In+iqRQdLHWz09H9K7HqhWxyZCb56hPzVEw0 8pXw== X-Gm-Message-State: AOAM532lHmlP6/qbzXtqhaljwWVP/l57bCIngcULE1c15bQrkwJufSU/ 98UwJxkzNjqbMJ3I6BPjCcwN+A+T302IJMta5Kb/NL9Dy8eYrr4h0BZ2kaSiC89EH2sSzfsuopH IbK4PP8t6zNNxuxfYSf9a+e9EityY6l8t7YZT4l3XAA== X-Received: by 2002:a17:906:d1c4:b0:6d5:83bb:f58a with SMTP id bs4-20020a170906d1c400b006d583bbf58amr17198184ejb.672.1646819532930; Wed, 09 Mar 2022 01:52:12 -0800 (PST) X-Received: by 2002:a17:906:d1c4:b0:6d5:83bb:f58a with SMTP id bs4-20020a170906d1c400b006d583bbf58amr17198172ejb.672.1646819532666; Wed, 09 Mar 2022 01:52:12 -0800 (PST) Received: from [192.168.0.144] (xdsl-188-155-174-239.adslplus.ch. [188.155.174.239]) by smtp.gmail.com with ESMTPSA id mp33-20020a1709071b2100b006db6dea7f9dsm373267ejc.168.2022.03.09.01.52.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Mar 2022 01:52:12 -0800 (PST) Message-ID: Date: Wed, 9 Mar 2022 10:52:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] NFC: port100: fix use-after-free in port100_send_complete Content-Language: en-US To: Pavel Skripkin , sameo@linux.intel.com, thierry.escande@linux.intel.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+16bcb127fb73baeecb14@syzkaller.appspotmail.com References: <20220308185007.6987-1-paskripkin@gmail.com> From: Krzysztof Kozlowski In-Reply-To: <20220308185007.6987-1-paskripkin@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,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 On 08/03/2022 19:50, Pavel Skripkin wrote: > 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 > --- > 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); Reviewed-by: Krzysztof Kozlowski Thanks, this looks good. I think I saw similar patterns also in other drivers, e.g. pn533. I will check it later, but if you have spare time, feel free to investigate. Similar cases (unresolved): https://syzkaller.appspot.com/bug?extid=1dc8b460d6d48d7ef9ca https://syzkaller.appspot.com/bug?extid=abd2e0dafb481b621869 https://syzkaller.appspot.com/bug?extid=dbec6695a6565a9c6bc0 Best regards, Krzysztof