Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp720585pxb; Tue, 5 Apr 2022 20:15:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjRJbjdMQFhIV3+cEB03x83uwCliDEXD84kfCinASNFKVVVWnovub7eACC3P4ZwS0YaZob X-Received: by 2002:a17:902:8ec3:b0:155:ff17:fb7 with SMTP id x3-20020a1709028ec300b00155ff170fb7mr6523322plo.135.1649214925361; Tue, 05 Apr 2022 20:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649214925; cv=none; d=google.com; s=arc-20160816; b=K5oY9NkY9dOuYIJmMgKGxsoWHPHemIXGAW1cMDxEV8TlXM9BLzjnysak/5I22g4W5/ soll7nvjFozU6CHa2swkSE6JmqkI11A/CoddmYronmW/QG1/kSHMf0bsiXU1FbOAMisS P6DpB/SIzCpgBpzI8IXi/bMevvAMWjbSsuJU7QZ6GTR/261tT1wDLUItIL28VLRAW5zD +d/JPGadyBgDF2US/B+nXSSgHTexbe0R+ueO0NPVcoDWbWGnALRwJsTxaT1vb09zTacz tjP6KQyP6Z0/zA7+BYioz7dOKlBQeBqXRun9C6OmomxysEQv+YN/KjISj2KzNrP9birz GtMA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ezu0tZj2fsI9LTW12qwJB2hm/N78kcxJT+H/jirc0r0=; b=Ki0IWeykAJwJ3HriBmAFRuwrBFa8F/vwYU+P1lXaxwtw+w2wGlp/61ltpEMpHqk+bN wcsbAv/4FAH1hBXhMvSY25QD//sI64auyZTxO4Xt4vgDyNN+bGLeOJnlkMd7hDp86Sxb +tcEzb6QOYfOrCzlx0n5pBQJ6lFwtU3cvA+gmdFSagFekFUQKIWjVkp9yiyyq5CFgsnG 7xbZO53Y+HAlxM5MiV0stCXxbhihh/d3tna9/G7SfxtuEN0o0ygxtR/QvgydMXgsPZm0 QHxg/LGs2wyVhy8i4R4d30N1g5KcpCcA/iZ2Hy7hobaU7EvLA/GF80jXwIL1+R3oz0lI m7IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SBVW5+qo; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h4-20020a170902b94400b001548f998293si13892270pls.518.2022.04.05.20.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 20:15:25 -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=@linuxfoundation.org header.s=korg header.b=SBVW5+qo; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1593A219957; Tue, 5 Apr 2022 19:53:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350992AbiDEMeN (ORCPT + 99 others); Tue, 5 Apr 2022 08:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235649AbiDEJCY (ORCPT ); Tue, 5 Apr 2022 05:02:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D7E7DF61; Tue, 5 Apr 2022 01:54:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E211B61511; Tue, 5 Apr 2022 08:54:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC9DEC385A0; Tue, 5 Apr 2022 08:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148857; bh=yfN8wMvdKf1VY7l+pXJwS8velMvH7lUD58otw87kh5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBVW5+qoIAXeQN651g/fxhHnWy0koSuyaeOCAnh2LLeokjCZTBaBo/qr2Nu+KOqiJ AJOkN81gIHBQMhbZGsedcxnAQFKUlakOIuZZpCj2LYjYFScbQR8he5gC+Cq/2iu7PI iB7hmM8mnJEIuClKJmqXhiZ/1G/Sf0m5q/ICGFJk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Widawsky , Dan Williams , Sasha Levin Subject: [PATCH 5.16 0505/1017] cxl/port: Hold port reference until decoder release Date: Tue, 5 Apr 2022 09:23:38 +0200 Message-Id: <20220405070409.289010755@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 From: Dan Williams [ Upstream commit 74be98774dfbc5b8b795db726bd772e735d2edd4 ] KASAN + DEBUG_KOBJECT_RELEASE reports a potential use-after-free in cxl_decoder_release() where it goes to reference its parent, a cxl_port, to free its id back to port->decoder_ida. BUG: KASAN: use-after-free in to_cxl_port+0x18/0x90 [cxl_core] Read of size 8 at addr ffff888119270908 by task kworker/35:2/379 CPU: 35 PID: 379 Comm: kworker/35:2 Tainted: G OE 5.17.0-rc2+ #198 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 Workqueue: events kobject_delayed_cleanup Call Trace: dump_stack_lvl+0x59/0x73 print_address_description.constprop.0+0x1f/0x150 ? to_cxl_port+0x18/0x90 [cxl_core] kasan_report.cold+0x83/0xdf ? to_cxl_port+0x18/0x90 [cxl_core] to_cxl_port+0x18/0x90 [cxl_core] cxl_decoder_release+0x2a/0x60 [cxl_core] device_release+0x5f/0x100 kobject_cleanup+0x80/0x1c0 The device core only guarantees parent lifetime until all children are unregistered. If a child needs a parent to complete its ->release() callback that child needs to hold a reference to extend the lifetime of the parent. Fixes: 40ba17afdfab ("cxl/acpi: Introduce cxl_decoder objects") Reported-by: Ben Widawsky Tested-by: Ben Widawsky Reviewed-by: Ben Widawsky Link: https://lore.kernel.org/r/164505751190.4175768.13324905271463416712.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams Signed-off-by: Sasha Levin --- drivers/cxl/core/bus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/cxl/core/bus.c b/drivers/cxl/core/bus.c index 46ce58376580..55e120350a29 100644 --- a/drivers/cxl/core/bus.c +++ b/drivers/cxl/core/bus.c @@ -182,6 +182,7 @@ static void cxl_decoder_release(struct device *dev) ida_free(&port->decoder_ida, cxld->id); kfree(cxld); + put_device(&port->dev); } static const struct device_type cxl_decoder_switch_type = { @@ -500,7 +501,10 @@ struct cxl_decoder *cxl_decoder_alloc(struct cxl_port *port, int nr_targets) if (rc < 0) goto err; + /* need parent to stick around to release the id */ + get_device(&port->dev); cxld->id = rc; + cxld->nr_targets = nr_targets; dev = &cxld->dev; device_initialize(dev); -- 2.34.1