Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp477981iob; Wed, 11 May 2022 19:54:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxPdWUkjPTYOwfEpFuN215RZkI8AIFvPotpdiqVmNnmLpTP7psz5kiNCDRolzr93Afc3Mq X-Received: by 2002:a05:6402:17c1:b0:428:8016:d98d with SMTP id s1-20020a05640217c100b004288016d98dmr25967942edy.5.1652324088434; Wed, 11 May 2022 19:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652324088; cv=none; d=google.com; s=arc-20160816; b=b/N+uGP45gf4vCQ6oUH3El5f3XmqPehwHWRYQN5r3QlSWyrHrIR9lb33IKpdoebO8W WaIGoNk+4h41IP6C7J3xHr/3yOWTUg1LifmveLEoIjvIEItXKpcmn4ZrMdWd44rOsB3X +muy4xCzmE/a1Un6pQEiAWeMP7BlJY9op3rTtOhcsEbDM/rP/R1+SsP4nZSmIQr/mklt P9isDADye09tp3NXuJiXeZ6eYykfgyVi8pSWfByhK++tt4sTrLETTYuRfQ7UHSIGEOqP Udml/xkhHACOAEsDchDnxOvazLs/RMIqlWrlr/eJa8sDKQ93e2h3YCj36GsKr3cRRCvX +egA== 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=c0q9lSthzZA9ebdoWrGjLlspxL9ScqJqzeHJj1mFYns=; b=E9IlFulSOGUcQTJ/AKYQjZWuWf1rnCp6FlhDk7bkyESBjw+rvQiyowB1ImQyspYrkh 8/0vlKR409MknRQu+KLxBdto8J2ldmmJ6VoDxLibAadwfGlFFB65vvTMHCxkC1UdwfKd EskTRjIeyJF20zkC8yXzOhLYORNV06FV05Wya9IwPDi4MDlZSnvbHLxklNiYL8KA4wik rOYWSUMK9skRR4T8XT6U63/kbYKtYgS9gIt7+Y7dMyyg8zjrfZV3lRSgp3AU1rqQlkH/ 1Fg6XVUJQQ2J54+NwHyi00KeMNIShdDtg9Q1Ax3shDCx/Jg4DlhxbpqwQZCp7OKwfbq4 Atiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GDn6VZwU; 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 hg5-20020a1709072cc500b006f3be6cce60si4559704ejc.786.2022.05.11.19.54.13; Wed, 11 May 2022 19:54:48 -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=20210112 header.b=GDn6VZwU; 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 S234731AbiEKNZX (ORCPT + 99 others); Wed, 11 May 2022 09:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242446AbiEKNZV (ORCPT ); Wed, 11 May 2022 09:25:21 -0400 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E974359BB6 for ; Wed, 11 May 2022 06:25:19 -0700 (PDT) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-deb9295679so2778722fac.6 for ; Wed, 11 May 2022 06:25:19 -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=c0q9lSthzZA9ebdoWrGjLlspxL9ScqJqzeHJj1mFYns=; b=GDn6VZwUdzoS/PZ3WZphP5KfT1waNs06jisSm83Jmg2BvTfSwzZete6ZPWfptb04rq g5gUU7fic3GIzM1Mgeq4JVyhRZapxoA3A5msRnO/lcN93aupjMeMB1YeJk5wDGEsh2s+ /otBPjaEM/keLmsADusUhUrkg9HGpi0c/zIlFTvtbzA2URjuV40krxeE8ivst2gpB10d KPsvuLy6lbiisozNE/mGASP7jdxF8LcLJaU7qwg1MDEaw6qxWAJ5KwY229psO1EdgQUj RQPqZq5elN4LeBdj+dxcQH2rYWZUA03ERM8kmtcUUl/uEzBUF/ixcHUkXxazJCFaYtqL JmZg== 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=c0q9lSthzZA9ebdoWrGjLlspxL9ScqJqzeHJj1mFYns=; b=faLGjOhBqyCLeB86velOMqbZNRBMcxfkDwCaX3jmFV7uWRpmOV8uu9AjNi8jvtcrdm RwTP09bhgfqOrLgcwVJtc7pLfX8Clxj8y1Cf1aFOyQ4sZJcJtj7sdzJNABQ47aO5ijq2 pyBqHYlRAuOAX/ujRoRMCKvECD0eCwTLcs6/DrGxBjfZvO4B1LfUcfj12hv/d7TFzK9b 6BbU/Iu5+b0oJ43nlvwBlUU/GlvI/QXj48yXiXa1d3or3GLQqv1z8N5uGVObyzkhWxNu Ba/ZtylVwDXpCd36Z/fmrJSlex5Q6/MfMBbBWaadpU+9MAh1DVq2teYAQXcFLk4ra/uj WQwA== X-Gm-Message-State: AOAM530KSLG6GurNpzwcYS83q95UOko1S2w+99PqXxhB8pzMTEbHm1Cn ax66biXRZZA4/6QFnLYDEermpK/4wpNU1xqDRiPpx2ogYEchPA== X-Received: by 2002:a05:6870:5b89:b0:e9:bb4c:a6f1 with SMTP id em9-20020a0568705b8900b000e9bb4ca6f1mr2718055oab.52.1652275519287; Wed, 11 May 2022 06:25:19 -0700 (PDT) MIME-Version: 1.0 References: <20220511124336.66705-1-schspa@gmail.com> In-Reply-To: From: Schspa Shi Date: Wed, 11 May 2022 21:25:08 +0800 Message-ID: Subject: Re: [PATCH] driver: base: fix UAF when driver_attach failed To: Greg KH Cc: "Rafael J. Wysocki" , ming.lei@canonical.com, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Greg KH writes: > On Wed, May 11, 2022 at 08:43:36PM +0800, Schspa Shi wrote: >> When driver_attach(drv); failed, the driver_private will be freed. >> But it has been added to the bus, which caused a UAF. >> >> To fix it, we need to delete it from the bus when failed. >> >> Fixes: 190888ac01d0 ("driver core: fix possible missing of device probe") >> >> Signed-off-by: Schspa Shi > > No blank line needed after fixes: > Do I need a new patch version for this ? >> --- >> drivers/base/bus.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/base/bus.c b/drivers/base/bus.c >> index 97936ec49bde..7ca47e5b3c1f 100644 >> --- a/drivers/base/bus.c >> +++ b/drivers/base/bus.c >> @@ -617,7 +617,7 @@ int bus_add_driver(struct device_driver *drv) >> if (drv->bus->p->drivers_autoprobe) { >> error = driver_attach(drv); >> if (error) >> - goto out_unregister; >> + goto out_del_list; >> } >> module_add_driver(drv->owner, drv); >> >> @@ -644,6 +644,8 @@ int bus_add_driver(struct device_driver *drv) >> >> return 0; >> >> +out_del_list: >> + klist_del(&priv->knode_bus); > > Odd, how did you find this? Has this ever been triggered by any > real-world situations? > I found this when fixing this issue via code review. Link: https://lore.kernel.org/all/20220508150247.38204-1-schspa@gmail.com/ It shouldn't not happen, unless the bus driver's match() return value < 0. Which never happens with the existing bus drivers. > thanks, > > greg k-h --- BRs Schspa Shi