Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp936778iob; Fri, 13 May 2022 17:04:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmrPoJij1YrZcZkbZoBKTEaxuykipdpzTYeXov0ZXgpSB8DOOuvPz7pdeyWloM5EMe4kvz X-Received: by 2002:adf:e809:0:b0:20c:df0d:e583 with SMTP id o9-20020adfe809000000b0020cdf0de583mr5672841wrm.241.1652486692441; Fri, 13 May 2022 17:04:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652486692; cv=none; d=google.com; s=arc-20160816; b=ezqmQyvRlRHS+Ys0Y+5ZEAwsquuRNZbAlusE9HI23jrm2MOGv21Ssbfw63M25GrkYA wf0AsQ97HL+u8BUKHp7w2NsRz7rFMCfZQ1QYCj2gkPiGSfiiqhKsHZInASLtM6ZKekRt 5EUHbcWoiAtv1wPPm5yo7DFFowHRbWiDO+sLqa9OXJkh/YAYf6LwMrNM0xSJ8tIRYwW9 DjjtILHuujBE5OUOqd+QKYHEqM8/GctPancsGgneP2B2ijQ+UPamZXbO6AMC9X7+cSTb cc6TtnCpAYRw3kY6GquWIjZX67ww/RhNZ0kO5b145XjbDjBR+e5WMkCFG6/lpYkdUO5N KEIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UE4ANBc0dyv3rKuUnMaCAbsStOruYiarl2aWFMtkOuk=; b=Acrotm5CJMcs1QtmYd2eQryADq8xLQOfRdfReolYtx2wGZgJ177XPXD5lIFh+DUzWe hZJt2emaIouWWH6iZWi26ppN1atttrvWkkAIpiUVVo+wy68eS84q3lEGavffrGKeMyLV on1ffFo1wy1i116kOI1RHXEtU2Pc50Q3vGcr2f75jhvfqTY2poMHZhzaiF0IdYBjmX2B ZuaKsfE4by/+vDTKEOBXvM4uNJAGVYLBgHlk3ycS7qwj/v3t3ku+h0REpiUmVd//BzaU bAa8/0qLolWHwgPxmRGu4e7LqN0U3CZ3kumThhpJYWcvVSN2rQwjv/sNQg3Pq3NCcZM9 5gnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AaBzSlnW; 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 r5-20020adff105000000b00207ad22507dsi3153374wro.366.2022.05.13.17.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:04:52 -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=AaBzSlnW; 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1791A2BA999; Fri, 13 May 2022 16:07:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379876AbiEMLZC (ORCPT + 99 others); Fri, 13 May 2022 07:25:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350675AbiEMLZA (ORCPT ); Fri, 13 May 2022 07:25:00 -0400 Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E2742A7C06 for ; Fri, 13 May 2022 04:25:00 -0700 (PDT) Received: by mail-qv1-xf2b.google.com with SMTP id jt15so6433195qvb.8 for ; Fri, 13 May 2022 04:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UE4ANBc0dyv3rKuUnMaCAbsStOruYiarl2aWFMtkOuk=; b=AaBzSlnW49zH06z7yi1ois+BrtxmqIe9mgTOZtnWiu4Ilto2+Fu4b3Mhi4Ax/r1x7n e2Qnif5FFcpu1uKeN3QYn6eseYKurLktuseBR/sw/wjuY55Wwk/fpcB7mB1a6CFX8bXO jK05ni5VBCc8THDLHDC5e88bs7d2hpsRMTV4NGEfgOEYeNllWaLqofN8VFK+jpjrdqQx XmU1O7+//ooeobHm1VbcsRzg6rzl/AQ1+CDBciu1jVwq8FN+OL+96tBaahkRjAsrjwcD lqQETAUNi8+2iO0jw62jyTo7AU2DrsroaF1fRit9xSC3a1NmM54BYL2EJhcIW23Vx+N5 S5LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=UE4ANBc0dyv3rKuUnMaCAbsStOruYiarl2aWFMtkOuk=; b=8M+S2KNV5trJcnEnKsGyOEPNSD1hs50Yq3xbWnFMefUKZ97u6VfZIfeQ9f/j2CRGVg n/TM9ae4CEygeP39+PP8kweTvCi+M+rj8xr9/kIf8/oUwGSN7Cwgj6Cq1w+TrzzQ46EG riRLexn2U5o6P76SemG67EEEg3NoyelgDUZxC0RYgvMFlzFwgsIAeCygiRagutXtPlxo k9nxo04MSZd9E13cmI+LeO0nATkRCrA2uB4caupc9DvZX8oxFiaLexPhx0VTexAfyPp4 GI8+YOv3G7NnuDgBV1BmD87Z1LD9MhMMtkE/mNbyQD9unSEOiGoE4/d5LF5Kpc/Tt9If ScvA== X-Gm-Message-State: AOAM533QaOiV5tUvTATVKjjUcSh4J/eImq/xzBVLLgbft2MPYrEq2hUN 3hDaiFMybMYv58oYgYXervk= X-Received: by 2002:a05:6214:509d:b0:45a:d14a:eb53 with SMTP id kk29-20020a056214509d00b0045ad14aeb53mr3762501qvb.40.1652441099174; Fri, 13 May 2022 04:24:59 -0700 (PDT) Received: from MBP.hobot.cc (ec2-13-59-0-164.us-east-2.compute.amazonaws.com. [13.59.0.164]) by smtp.gmail.com with ESMTPSA id j28-20020a05620a147c00b0069fcc501851sm1208618qkl.78.2022.05.13.04.24.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 May 2022 04:24:58 -0700 (PDT) From: Schspa Shi To: gregkh@linuxfoundation.org, rafael@kernel.org Cc: linux-kernel@vger.kernel.org, schspa@gmail.com Subject: [PATCH v2] driver: base: fix UAF when driver_attach failed Date: Fri, 13 May 2022 19:24:44 +0800 Message-Id: <20220513112444.45112-1-schspa@gmail.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- Changelog: v1 -> v2: - Remove the blank line needed after fixes --- 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); out_unregister: kobject_put(&priv->kobj); /* drv->p is freed in driver_release() */ -- 2.29.0