Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp59749lfe; Fri, 15 Apr 2022 19:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBhUUhpSwqhX7KhTAnRXXoJT24JaXVFVOsXK7PXVFE8SfNh0ZLLze3kXDvRjl5cVlguOWM X-Received: by 2002:a17:902:8608:b0:158:c532:d8b2 with SMTP id f8-20020a170902860800b00158c532d8b2mr1576537plo.46.1650076098412; Fri, 15 Apr 2022 19:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076098; cv=none; d=google.com; s=arc-20160816; b=sI6zY0OFyAAtKfr3hDoJ5gipa+ic6JMllTp39M51Pzd+UNu/sJnxruBELR9onMFtBo UJQ76yZCHB7fd8hAtGsaSff+Y3w9ejUOocmhJnxY3Ub8pqT+POshO/gYv14SwQN/CXZw FYITvFczIa+PD3HLojUoLP64BfCUuyMjAMaMglleE38NzcTFMpScSCGGn4tFybGf0Gip 2MxboTsZJpw3k62yTM+YCLjoylruxVCMXa2ciZgc5mmk8eKLGGRvNquWnpAnrqvN3XZP nx1bj6qQuSE5I53Ox3c32WVRioQQAJpl+Tp9xUAUUf/OW2IhuvaI7obi7OkHgQlbp0f2 kgxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/E+AcAaSNTGwLrIM9dnK9ucwkz5tYLhaR9fA3ICo8Pc=; b=D1Ozwz1qyI/N/SX/kLOOuz8N0mXozKsDUAZppFfHLYkbb2FUOKd/lo/JeHxa4LHfOg wltMdHuwUsGHFBYzWtkyWhDNJ/bjF/BtDlmD2sMCvgwWmtzr/+G8S2UWSw+ODH/Do5B/ mVj7QcO3tJvDAgd7n7A30WbfRQ7EN79vnTnKilEQtVnoMdl0JSKyfZ+OgEYDGGiLLCwh kW+msDM/jkflW1x/osPFLxGBknHHp1ry8BbQy/kYCu/S3jTm83LptTFIcFzX5ohhb4hU mUi2/M9jXFe8jTf9+pPT39udgDxyvly+E3tPhv/1rKG5pmqSO1eVIOveuPRVf3Asox4Z IXHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y73-20020a638a4c000000b0039d54720b7fsi3048379pgd.778.2022.04.15.19.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:28:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 948D4122225; Fri, 15 Apr 2022 18:40:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350955AbiDOHXF (ORCPT + 99 others); Fri, 15 Apr 2022 03:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350951AbiDOHWc (ORCPT ); Fri, 15 Apr 2022 03:22:32 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D820B30F6B for ; Fri, 15 Apr 2022 00:20:04 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nfGF5-0002Un-O5; Fri, 15 Apr 2022 09:19:43 +0200 Received: from ore by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1nfGF1-0005Kb-US; Fri, 15 Apr 2022 09:19:39 +0200 Date: Fri, 15 Apr 2022 09:19:39 +0200 From: Oleksij Rempel To: Andy Shevchenko Cc: Johan Hovold , Oleksij Rempel , Dongliang Mu , Oliver Neukum , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Dongliang Mu , syzbot+eabbf2aaa999cc507108@syzkaller.appspotmail.com, USB , netdev , Linux Kernel Mailing List Subject: Re: [PATCH] driver: usb: nullify dangling pointer in cdc_ncm_free Message-ID: <20220415071939.GB27951@pengutronix.de> References: <20220409120901.267526-1-dzm91@hust.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 09:17:12 up 15 days, 19:46, 42 users, load average: 0.02, 0.08, 0.16 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 Thu, Apr 14, 2022 at 06:01:57PM +0300, Andy Shevchenko wrote: > On Mon, Apr 11, 2022 at 9:33 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(). > > Good question. Isn't it the commit 2c9d6c2b871d ("usbnet: run unbind() > before unregister_netdev()") which changed the ordering of the > interface shutdown and basically makes this race happen? I don't see > how we can guarantee that IOCTL won't be called until we quiescence > the network device — my understanding that on device surprise removal > we have to first shutdown what it created and then unbind the device. > If I understand the original issue correctly then the problem is in > usbnet->unbind and it should actually be split to two hooks, otherwise > it seems every possible IOCTL callback must have some kind of > reference counting and keep an eye on the surprise removal. > > Johan, can you correct me if my understanding is wrong? Hi, the possible fix for this issue is under discussion here: https://lore.kernel.org/netdev/d13e3a34-7e85-92dd-d0c0-5efb3fb08182@suse.com/T/ Regards, Oleksij -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |