Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1014672pxb; Fri, 15 Apr 2022 18:24:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaaAytpCaB1UFBCwxieYttt2PHAU0LEhMA6wODIUiupN5KCqKQT7deiX4V901R30RvB7A3 X-Received: by 2002:a17:90a:4604:b0:1bc:8bdd:4a63 with SMTP id w4-20020a17090a460400b001bc8bdd4a63mr6865888pjg.147.1650072256552; Fri, 15 Apr 2022 18:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650072256; cv=none; d=google.com; s=arc-20160816; b=Ultvq07uEQ+2zVwCk2W55IaveNcH2bje/AyUY5PhujeX1hgeY+6gVHebI/jhUWRliY bXtPfGZvzaabXRzfV4LBF6kqqWfYnEKKxjcPA0k4XnH9Kv8yZw8I/RjqDcDqPc3QPmE+ HPSk0hmsL056xd1alf8hrG8/cZ0Fa+C9dhIbwj9Ana4bHA0NF0LB4OnkS0U+3HtgN/c8 ajLn4Mb/VMxEBBXUCIb/x31OdjKfGPaHIzWA7Dl8rSZhCnzyF7JxJb7ay77sWtDVYUIb WAJy0UGCM0w82roTqfrJmaefeHbBTZzWbhL4dfsJpLhG7vvPuuxxQceRzGTgOWdB/FWa 8GMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hNy9y1b65287PSbSI4vGYvbgs90ln0eXu+3fCm9FcOI=; b=cKQvWmx/cT97y1gfkyqfb3aTEsJOTEdbd3M/Zwj3hBEAbuOvw9vAo5VBD0+twtsK4a MiYQ0+ELO7B5ePDWUI4ApjhyCtuB0wQkdzgY1AoDwncspbPoy5jQ6TLEFukHqdo+VTQz iQPtLPoALd+Gh+goUnNKx5YuBeJuo4nHx14e68xYeAfsaJIEXp+gkJokzUlS+eTjdika j9GdPM+WUUM60Xw7A6yRTlXxg8xI671pSEO4wbY2lco+k6A6ERHsFLdmnr6udhgawQ/+ yBq+6JllCrVcfpzpnPBa/v3K5Xc7IwwFsRJmIecKcm+PSX3k0mf4FLnnrPzhr0eW0FuT BzjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Au05tlXg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d18-20020a170903231200b001540e087687si3055578plh.198.2022.04.15.18.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Au05tlXg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE1CF113D29; Fri, 15 Apr 2022 17:55:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240225AbiDNP1O (ORCPT + 99 others); Thu, 14 Apr 2022 11:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348131AbiDNOCS (ORCPT ); Thu, 14 Apr 2022 10:02:18 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FB8FAE4F; Thu, 14 Apr 2022 06:58:48 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id z12so6495563edl.2; Thu, 14 Apr 2022 06:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hNy9y1b65287PSbSI4vGYvbgs90ln0eXu+3fCm9FcOI=; b=Au05tlXgQtSXjltxV1n2izruU5VhEEdX23KtSYxE3VRKNwwOjHeYAoNWWwVSMFqzZl NMaXkWm4DPxbdnRBSvk3w8t/2I+N3wiEzH845zEa9fOmF1dB8tadMr4RIzhTdkmd5yYa Y6rvC3n0PfygYTIR2xlJpF4I2Bv5Nkeky8V+UKh0Gh9Q/hQGDM+Er336xNoDsU4v79V2 qeLLBc0zfjWa9q1cGuyd3zNAqNrTxCPefK7/9+6oGC4COfvVzV69qX3JyFfHR5Q9QvJJ cv5hUPRhzxzvixQFazN0/WKJKSYDeP11pQf+HN4O+32TDufXvMrEIWhVBYiBLMIm7D18 HOQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hNy9y1b65287PSbSI4vGYvbgs90ln0eXu+3fCm9FcOI=; b=XUN7Ato6+faGgTpybkIqIb8kK3xHoB5MwXrMMr59vWywPHMV82fBm1E0M9npDIqd7G 2b3G33x4KiLrrQoi9ndartQ1jhtwugERu/DDlwz1/DyE7fg5f+gAHZtTyvzwWwcoAF5S lXRvFsbDjkAGjs3S8S/6/9p1MSfGFEnkYzfVn8tW6xkgszM0oT6xu06BekuuFVZJsrdD FoikSxE5liqCPh9SfSGEZoCI1HRWxn/wqyxD3t1OiGVggdBC8AoMZtwHtkLUyCl1J812 LGuB/9rNnM+XRHuniowYunbdCXf5umDrbRuCoIEscO7N5hJB/Ya+RvAmU8N1SgQYuMWD eYVQ== X-Gm-Message-State: AOAM533SH87fkphY43GmcMR4RAV/KcfU28XRmfr1bHkiCwhbwRJbd7cl ryyQnp59wrqJANx2h2tVhK4AhVb3wmlYG+YTlYo= X-Received: by 2002:a05:6402:2788:b0:41b:c871:715b with SMTP id b8-20020a056402278800b0041bc871715bmr3148078ede.53.1649944726651; Thu, 14 Apr 2022 06:58:46 -0700 (PDT) MIME-Version: 1.0 References: <20220409120901.267526-1-dzm91@hust.edu.cn> In-Reply-To: From: Dongliang Mu Date: Thu, 14 Apr 2022 21:58:20 +0800 Message-ID: Subject: Re: [PATCH] driver: usb: nullify dangling pointer in cdc_ncm_free To: Johan Hovold Cc: Dongliang Mu , Oliver Neukum , "David S. Miller" , Jakub Kicinski , Paolo Abeni , syzbot+eabbf2aaa999cc507108@syzkaller.appspotmail.com, linux-usb@vger.kernel.org, "open list:NETWORKING [GENERAL]" , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Mon, Apr 11, 2022 at 8:14 PM Johan Hovold wrote: > > On Sat, Apr 09, 2022 at 08:09:00PM +0800, Dongliang Mu wrote: > > From: Dongliang Mu > > > > cdc_ncm_bind calls cdc_ncm_bind_common and sets dev->data[0] > > with ctx. However, in the unbind function - cdc_ncm_unbind, > > it calls cdc_ncm_free and frees ctx, leaving dev->data[0] as > > a dangling pointer. The following ioctl operation will trigger > > the UAF in the function cdc_ncm_set_dgram_size. > > > > Fix this by setting dev->data[0] as zero. > > This sounds like a poor band-aid. Please explain how this prevent the > ioctl() from racing with unbind(). You mean the following thread interlaving? ioctl unbind cdc_ncm_free(ctx); dev->data[0] dev->data[0] = 0; It seems this will still trigger UAF. Maybe we need to add mutex to prevent this. But I am not sure. > > Johan > > > ================================================================== > > BUG: KASAN: use-after-free in cdc_ncm_set_dgram_size+0xc91/0xde0 > > Read of size 8 at addr ffff8880755210b0 by task dhcpcd/3174 > > > > 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+0xeb/0x495 mm/kasan/report.c:313 > > print_report mm/kasan/report.c:429 [inline] > > kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491 > > cdc_ncm_set_dgram_size+0xc91/0xde0 drivers/net/usb/cdc_ncm.c:608 > > cdc_ncm_change_mtu+0x10c/0x140 drivers/net/usb/cdc_ncm.c:798 > > __dev_set_mtu net/core/dev.c:8519 [inline] > > dev_set_mtu_ext+0x352/0x5b0 net/core/dev.c:8572 > > dev_set_mtu+0x8e/0x120 net/core/dev.c:8596 > > dev_ifsioc+0xb87/0x1090 net/core/dev_ioctl.c:332 > > dev_ioctl+0x1b9/0xe30 net/core/dev_ioctl.c:586 > > sock_do_ioctl+0x15a/0x230 net/socket.c:1136 > > sock_ioctl+0x2f1/0x640 net/socket.c:1239 > > vfs_ioctl fs/ioctl.c:51 [inline] > > __do_sys_ioctl fs/ioctl.c:870 [inline] > > __se_sys_ioctl fs/ioctl.c:856 [inline] > > __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856 > > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > > do_syscall_64+0x35/0x80 arch/x86/entry/common.c:80 > > entry_SYSCALL_64_after_hwframe+0x44/0xae > > RIP: 0033:0x7f00859e70e7 > > RSP: 002b:00007ffedd503dd8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 > > RAX: ffffffffffffffda RBX: 00007f00858f96c8 RCX: 00007f00859e70e7 > > RDX: 00007ffedd513fc8 RSI: 0000000000008922 RDI: 0000000000000018 > > RBP: 00007ffedd524178 R08: 00007ffedd513f88 R09: 00007ffedd513f38 > > R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 > > R13: 00007ffedd513fc8 R14: 0000000000000028 R15: 0000000000008922 > > > > > Reported-by: syzbot+eabbf2aaa999cc507108@syzkaller.appspotmail.com > > Signed-off-by: Dongliang Mu > > --- > > drivers/net/usb/cdc_ncm.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c > > index 15f91d691bba..9fc2df9f0b63 100644 > > --- a/drivers/net/usb/cdc_ncm.c > > +++ b/drivers/net/usb/cdc_ncm.c > > @@ -1019,6 +1019,7 @@ void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf) > > > > usb_set_intfdata(intf, NULL); > > cdc_ncm_free(ctx); > > + dev->data[0] = 0; > > } > > EXPORT_SYMBOL_GPL(cdc_ncm_unbind);