Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3637779rwe; Mon, 17 Apr 2023 00:51:29 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUCPHCtSlvird54mSygzOG+G9/omsPkA4Mh2QGcMP5VUGuPAdT9OIjmPKBimqk4Wz9ITGZ X-Received: by 2002:a05:6a00:ccc:b0:634:c780:5bb8 with SMTP id b12-20020a056a000ccc00b00634c7805bb8mr21788083pfv.17.1681717889034; Mon, 17 Apr 2023 00:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681717889; cv=none; d=google.com; s=arc-20160816; b=OdEtfoUEnGiloLZlDOUA3iE1pQDWc5DH6gv2nFVusfAHYHuWIMMQLjnAs3ySJFB9Vs HNsZ5pHvuGxsxZ8mQTQYCGoKO9rIh+tmuWXjejDSPOHolg/hGkmaX258XwyTVEXPjCpX mCH8pTyaDeZLTVGWAFhL2Aq+WZGXULyvndh+NK+ZmmMhbgCvS/e+B2hjF5e1rSBN2ZE6 qpnqXfau8ioZVtZOnalGqe7YBmXfqTOK5GGn86c/OnwyVPC13qXYhoRBQURInHCWIDpT Rj+v3pX330SptizwPvjuDjVMwiJfGkk2foL3VRNmfCpR6MwDr7w/0OSy2XXHAqa/Kr4T L7CQ== 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-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=YRU9lV9y26BEe5IYQ0m1sVCYlPdalRoZZROP0jFCc0o=; b=pjohD9hhwdfVFXpbx/M0tUdAiOzyMn53fU8P7bGiSrWtupbXPw+t0bpKsKPsY9LtM1 I26at+jBiYOmma8FopGlNyjcCbMwmFzFN4+4F89IaTrnOqN6nzBdomXsFtO+XNgbQDz0 YYHBIOqb4lyYPyQhVMBAN5kgSuoTgM91lYB+ex/WgQIP83vbfnKWiy7z1x2o6IaGINvA 87CwrAmD4OZOeVI1/6dwr4kHC/xnE4eCZwEOO33z6kAeoEXktXC6PjPIGQaeYWotPqu9 h0szfqdDvTlEQCM4YHxhsa2Rkc5wk7gJk1nJbKOBYCTrlCQD0bOpeX1dKTII7v79Gl+U n7hA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a056a0000c500b006260200cd0asi10939741pfj.368.2023.04.17.00.51.15; Mon, 17 Apr 2023 00:51:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbjDQHqi (ORCPT + 99 others); Mon, 17 Apr 2023 03:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbjDQHqh (ORCPT ); Mon, 17 Apr 2023 03:46:37 -0400 Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [IPv6:2a01:37:1000::53df:5f64:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2652A8; Mon, 17 Apr 2023 00:46:35 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id E6437300002CD; Mon, 17 Apr 2023 09:46:33 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id D4A1D3CB3B; Mon, 17 Apr 2023 09:46:33 +0200 (CEST) Date: Mon, 17 Apr 2023 09:46:33 +0200 From: Lukas Wunner To: Niklas Schnelle Cc: Bjorn Helgaas , Gerd Bayer , Matthew Rosato , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Andy Shevchenko Subject: Re: [PATCH v2 1/4] PCI: s390: Fix use-after-free of PCI resources with per-function hotplug Message-ID: <20230417074633.GA12881@wunner.de> References: <20230306151014.60913-1-schnelle@linux.ibm.com> <20230306151014.60913-2-schnelle@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230306151014.60913-2-schnelle@linux.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, 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 On Mon, Mar 06, 2023 at 04:10:11PM +0100, Niklas Schnelle wrote: > --- a/drivers/pci/bus.c > +++ b/drivers/pci/bus.c > @@ -76,6 +76,27 @@ struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n) > } > EXPORT_SYMBOL_GPL(pci_bus_resource_n); > > +void pci_bus_remove_resource(struct pci_bus *bus, struct resource *res) > +{ > + struct pci_bus_resource *bus_res, *tmp; > + int i; > + > + for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { > + if (bus->resource[i] == res) { > + bus->resource[i] = NULL; > + return; > + } > + } > + > + list_for_each_entry_safe(bus_res, tmp, &bus->resources, list) { > + if (bus_res->res == res) { > + list_del(&bus_res->list); > + kfree(bus_res); > + return; > + } > + } > +} I realize this has already been applied so s390.git/master, but nevertheless would like to point out there's a handy pci_bus_for_each_resource() helper which could have been used here instead of the for-loop. Sorry for chiming in late, I just spotted this while flushing out my inbox. Adding Andy to cc: who's been active in this area recently. Thanks, Lukas