Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3729851rwr; Sat, 22 Apr 2023 10:27:43 -0700 (PDT) X-Google-Smtp-Source: AKy350avdcuaf8Hpu9wXazbeBE9gWHcml5/qmYOhNMfFow8MDihA6YQ5Uygh2pDNzZAkM523pN7Q X-Received: by 2002:a17:902:e5c3:b0:1a6:5f92:3ba with SMTP id u3-20020a170902e5c300b001a65f9203bamr10766486plf.0.1682184463311; Sat, 22 Apr 2023 10:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682184463; cv=none; d=google.com; s=arc-20160816; b=g3nLCZef3p+6LrsbQ1rculyx9cWvJt0jUqd0cvmY4qSQ3cfodn47+H4yWruJIQShXP 85C+K7yMXze5wk7ByA+1ZZ1vp2WCHTmqU148YB/2t/WMMc9jonDHOc0gsT1Begh7SgRT 5LG/lRwdu6w/0DbLJn3enez9mf9hnaYgnVyPfiJMBtNi9q2CU0vb/ClO/Oi5TCwSvbK1 1VyG/LmjWoLHtjyHBbC/Yu/XioGOjr1h/00kjXs49ZS1eN+4uGJH0zdFdMB1ucGqJil0 PDX/03pv8h8yv8qv5kKClDmymnQVDbTMoLXhNoMsi2I+JEakFxepqjVsAA8DOE47ZQyS wBSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Wk2042zfNAUEsSfOk/Grl8pMqFin7l2KkxbaVxctjkE=; b=h+9EVt+HimfEsd9aiVOLLs04ms+Z32bjhAjfDGJeWHkaLFlyqLzlZps+6Fr59LEdYt TVM0NYxplyVacZQ6APIzedPfTXJMdr/85MmkSbXiR6PLCGoNH/sNgBOQI/sut9oLdf/f OmXkbBJrD4EFI73zmFygRu4VI9yrHmC8Ers+9g8pSFiP1+DE+v+CUnAPW+pmjhm2qddo phhSVsDKpU3B3zBe+R3KOa6x0VL8aaCA7HEIMNh7+jOLEOskOYhuFG5o0n26Dg4SLRhW xxcY74TrhFowNRrF6kal4CzPc9chzMFJxqdY/QGR9rWGn0bKUouSINEche7Xmbp0FPUS ATbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=dFbCw366; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n16-20020a170903111000b001a23bf7a7b9si3725673plh.501.2023.04.22.10.27.29; Sat, 22 Apr 2023 10:27:43 -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=@gmail.com header.s=20221208 header.b=dFbCw366; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbjDVRJm (ORCPT + 99 others); Sat, 22 Apr 2023 13:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjDVRJl (ORCPT ); Sat, 22 Apr 2023 13:09:41 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8553C2114 for ; Sat, 22 Apr 2023 10:09:39 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-51b661097bfso2447917a12.0 for ; Sat, 22 Apr 2023 10:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682183378; x=1684775378; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Wk2042zfNAUEsSfOk/Grl8pMqFin7l2KkxbaVxctjkE=; b=dFbCw366hsVpu6+RVxsTm6f0iw+Ajze0I2LLToOn3MhBIqcCUgQQ++JaE1q9vKrqyj TaHniYHmRWwts4uYpktfYSgCqi7296zfu2AnRSVNUZlIhsJTpTR5v17OhfSojkqTJHOI DUMWWa27HvvQ7hxgYexV2CSKQ86lGWuf+na8dWSCj3YW7O1G+8awy8wB2d1xOBefmNPs EKcuDGCO7qzedMmqEFQwVG5V0cOZzcbeRSQCqqGVDGENEl/vX18NJj/EOufCnxP1Yvr7 pQ0yMjcd0VqtwThn8HKYVzxHCdzcptjgviEPorGqbUJf2kd8B8wqeZr75s8lMY/rllKB RzAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682183378; x=1684775378; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wk2042zfNAUEsSfOk/Grl8pMqFin7l2KkxbaVxctjkE=; b=ZCSd55OC3wkS986pISSBEaM8V7uVlUhEDUXrl7noxg40FyYuHCZ7OExvSt3SHeU6p9 Z0gA8Yr/i4/WW9T1c9vKbXglhxkPZvnQ5hxJt6O3G8lvZmMXiaQ5GcFEraCM3hPzG3fW BOXDHBHfabp9OIT1t9nuGsTDEX1L8v2Ejgj7oCbmnduwMzM9T8HM/J4MhNtoAyVN9kfQ p4XxHDx9MMWJdI5dIc4e4K1nkiKPfnTlb0cP6hdFVxWUuzVM3jEt641MNN9PhaKum4NV 2KOVKeur5IPhVUnk78MccswKKuEhk8RzUUwD/pxnvKO2AVS8DpnG3QL4kMnTtNreQfNx yIkw== X-Gm-Message-State: AAQBX9fm1qU5wIyhgtfRMiGiAwvuHXz9/WFbk3wCUIhqZsaiBDelYdNM ns3nyH1x0EXrw7hByJWHcyz8ryYPt/neECjoQ5k= X-Received: by 2002:a17:90a:398c:b0:23f:58a2:7d86 with SMTP id z12-20020a17090a398c00b0023f58a27d86mr9055879pjb.10.1682183377949; Sat, 22 Apr 2023 10:09:37 -0700 (PDT) MIME-Version: 1.0 References: <20230312145305.1908607-1-zyytlz.wz@163.com> <2023041308-nerd-dry-98a6@gregkh> <2023041308-unvisited-slinky-a56f@gregkh> In-Reply-To: From: Zheng Hacker Date: Sun, 23 Apr 2023 01:09:26 +0800 Message-ID: Subject: Re: [PATCH] misc: hisi_hikey_usb: Fix use after free bug in hisi_hikey_usb_remove due to race condition To: Yongqin Liu Cc: Greg KH , John Stultz , Zheng Wang , Sumit Semwal , arnd@arndb.de, linux-kernel@vger.kernel.org, 1395428693sheep@gmail.com, alex000young@gmail.com, Mauro Carvalho Chehab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Yongqin Liu =E4=BA=8E2023=E5=B9=B44=E6=9C=8821=E6= =97=A5=E5=91=A8=E4=BA=94 23:42=E5=86=99=E9=81=93=EF=BC=9A > > HI, Zheng > > Thanks for the explanation! > BTW, from what I tested, I am OK to have this change merged. > Hi Yongqin, Thanks for your testing and review. Best regards, Zheng > Thanks, > Yongqin Liu > On Fri, 21 Apr 2023 at 10:35, Zheng Hacker wro= te: > > > > Yongqin Liu =E4=BA=8E2023=E5=B9=B44=E6=9C=8820= =E6=97=A5=E5=91=A8=E5=9B=9B 14:31=E5=86=99=E9=81=93=EF=BC=9A > > > > > > Hi, Zheng > > > > > > BTW, I just see cancel_delayed_work_sync is used in > > > the drivers/usb/common/usb-conn-gpio.c usb_conn_remove function. > > > https://android.googlesource.com/kernel/common/+/refs/heads/andro= id-mainline/drivers/usb/common/usb-conn-gpio.c#274 > > > > > > I know nothing about the cancel_delayed_work_sync and cancel_work_syn= c > > > functions, > > > just for your information in case cancel_delayed_work_sync might be > > > better to be used here. > > > > > > > HI Yongqin, > > > > Thanks for your kind reminder. The cancel_delayed_work_sync is used > > with INIT_DELAYED_WORK and queue_delayed_work. > > This is used to start a work after some time while schedule_work means > > start it immediately. > > > > In this case, the &hisi_hikey_usb->work is initialized with INIT_WORK > > and scheduled with schedule_work. So I think we'd better use > > cancel_work_sync here. I'm also not so familiar with the code. If > > there's something wrong with it, please feel free to let me know. > > > > Best regards, > > Zheng > > > > > > > Thanks, > > > Yongqin Liu > > > On Tue, 18 Apr 2023 at 21:18, Zheng Hacker = wrote: > > > > > > > > Yongqin Liu =E4=BA=8E2023=E5=B9=B44=E6=9C= =8818=E6=97=A5=E5=91=A8=E4=BA=8C 01:31=E5=86=99=E9=81=93=EF=BC=9A > > > > > > > > > > Hi, Zheng > > > > > > > > > > Sorry for the late reply. > > > > > > > > > > I tested this change with Android build based on the ACK > > > > > android-mainline branch. > > > > > The hisi_hikey_usb module could not be removed with error like th= is: > > > > > console:/ # rmmod -f hisi_hikey_usb > > > > > rmmod: failed to unload hisi_hikey_usb: Try again > > > > > 1|console:/ # > > > > > Sorry I am not able to reproduce any problem without this commit, > > > > > but I do not see any problem with this change applied either. > > > > > > > > > > If there is any specific things you want to check, please feel fr= ee let me know > > > > > > > > > > > > > Hi Yongqin, > > > > > > > > Thanks for your testing. I have no more questions about the issue. > > > > > > > > Best regards, > > > > Zheng > > > > > > > > > Thanks, > > > > > Yongqin Liu > > > > > > > > > > > > > > > On Fri, 14 Apr 2023 at 00:46, Zheng Hacker wrote: > > > > > > > > > > > > Greg KH =E4=BA=8E2023=E5=B9=B44=E6= =9C=8813=E6=97=A5=E5=91=A8=E5=9B=9B 23:56=E5=86=99=E9=81=93=EF=BC=9A > > > > > > > > > > > > > > On Thu, Apr 13, 2023 at 11:35:17PM +0800, Zheng Hacker wrote: > > > > > > > > Greg KH =E4=BA=8E2023=E5=B9=B4= 4=E6=9C=8813=E6=97=A5=E5=91=A8=E5=9B=9B 20:48=E5=86=99=E9=81=93=EF=BC=9A > > > > > > > > > > > > > > > > > > On Thu, Apr 13, 2023 at 07:12:07PM +0800, Zheng Hacker wr= ote: > > > > > > > > > > Yongqin Liu =E4=BA=8E2023=E5= =B9=B44=E6=9C=8813=E6=97=A5=E5=91=A8=E5=9B=9B 18:55=E5=86=99=E9=81=93=EF=BC= =9A > > > > > > > > > > > > > > > > > > > > > > Hi, Zheng > > > > > > > > > > > > > > > > > > > > > > On Thu, 13 Apr 2023 at 16:08, Zheng Hacker wrote: > > > > > > > > > > > > > > > > > > > > > > > > Friendly ping about the bug. > > > > > > > > > > > > > > > > > > > > > > Sorry, wasn't aware of this message before, > > > > > > > > > > > > > > > > > > > > > > Could you please help share the instructions to repro= duce the problem > > > > > > > > > > > this change fixes? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hi Yongqin, > > > > > > > > > > > > > > > > > > > > Thanks for your reply. This bug is found by static anal= ysis. There is no PoC. > > > > > > > > > > > > > > > > > > > > >From my personal experience, triggering race condition= bugs stably in > > > > > > > > > > the kernel needs some tricks. > > > > > > > > > > For example, you can insert some sleep-time code to slo= w down the > > > > > > > > > > thread until the related object is freed. > > > > > > > > > > Besides, you can use gdb to control the time window. Al= so, there are > > > > > > > > > > some other tricks as [1] said. > > > > > > > > > > > > > > > > > > > > As for the reproduction, this attack vector requires th= at the attacker > > > > > > > > > > can physically access the device. > > > > > > > > > > When he/she unplugs the usb, the remove function is tri= ggered, and if > > > > > > > > > > the set callback is invoked, there might be a race cond= ition. > > > > > > > > > > > > > > > > > > How does the removal of the USB device trigger a platform= device > > > > > > > > > removal? > > > > > > > > > > > > > > > > Sorry I made a mistake. The USB device usually calls discon= nect > > > > > > > > callback when it's unpluged. > > > > > > > > > > > > > > Yes, but you are changing the platform device disconnect, not= the USB > > > > > > > device disconnect. > > > > > > > > > > > > > > > What I want to express here is When the driver-related devi= ce(here > > > > > > > > it's USB GPIO Hub) was removed, the remove function is trig= gered. > > > > > > > > > > > > > > And is this a patform device on a USB device? If so, that's = a bigger > > > > > > > problem that we need to fix as that is not allowed. > > > > > > > > > > > > No this is not a platform device on a USB device. > > > > > > > > > > > > > > > > > > > > But in looking at the code, it does not seem to be that at al= l, this is > > > > > > > just a "normal" platform device. So how can it ever be remov= ed from the > > > > > > > system? (and no, unloading the driver doesn't count, that ca= n never > > > > > > > happen on a normal machine.) > > > > > > > > > > > > > > > > > > > Yes, I finally figured out your meaning. I know it's hard to un= plug > > > > > > the platform device > > > > > > directly. All I want to express is that it's a theoretical meth= od > > > > > > except rmmod. I think it's better to fix the bug. But if the > > > > > > developers think it's practically impossible, I think there's n= o need > > > > > > to take further action. > > > > > > > > > > > > Sorry for wasting your time and thanks for your explanation. > > > > > > > > > > > > Best regards, > > > > > > Zheng > > > > > > > > > > > > > thanks, > > > > > > > > > > > > > > greg k-h > > > > > > > > > > > > > > > > > > > > -- > > > > > Best Regards, > > > > > Yongqin Liu > > > > > --------------------------------------------------------------- > > > > > #mailing list > > > > > linaro-android@lists.linaro.org > > > > > http://lists.linaro.org/mailman/listinfo/linaro-android > > > > > > > > > > > > -- > > > Best Regards, > > > Yongqin Liu > > > --------------------------------------------------------------- > > > #mailing list > > > linaro-android@lists.linaro.org > > > http://lists.linaro.org/mailman/listinfo/linaro-android > > > > -- > Best Regards, > Yongqin Liu > --------------------------------------------------------------- > #mailing list > linaro-android@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/linaro-android