From nobody Fri Dec 27 17:02:56 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YKWyn1PFSz5j2vh; Fri, 27 Dec 2024 17:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YKWyn0qyVz4twm; Fri, 27 Dec 2024 17:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735318977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qgyEAHkEveiJMrGiu2TUjnhu9lpOV7m8GaVXGEPZtzw=; b=AAim15E6Q0phRF8ChXJOhM0shm81ACpdOvAJWCpPi02vo35qC7qxA8nRbJ7AUd+ekyd7sB h8r/xgU+Wj2u1bWI1hFf6zxOplUQfjn9Vin06q3hR+My2rbLyayl6IQ//tWkjL2bUjjWpf pC0hhiK3c8NcuRPUhnOn1PqPf+Q1ed+Dg2RQ4k6bZBl41dea8b05H8jfWm561aTijIGva6 xN3wsA/mlMyzYqG6udYXmW+Y8SNn8aJ+Z86Q3PsRrOFXer5wG0OGOZzOcoKGQmkijjs9KK M5HG29oLSdFbALsOibSeumNI2KodK6/QeYaqJK5PjCtMTMGXbgZ8kkh9IVRdkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735318977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qgyEAHkEveiJMrGiu2TUjnhu9lpOV7m8GaVXGEPZtzw=; b=UjYtmvgIZ2U6pdHU2uMJwnF1V+UKIUJFyOClLCwrRBMAdinmx612hnOPITjLd0NVJMFPkA J9V7F6ufDb2PZR3A1xMeLQhhQUFVOTAdWLlKN8e51cJbqIoisljkwOSPqTKXWDOgsfSD4D w54tCAn2W/xcju5ZjpDsvA4Bt5v48BP2lmy9i9VuRHeiOKA9AvyzSXR6UAHjB88MlJKLWb 7alEYTQeLvmUQugavfrRMzoXOFtEd7ET7rOOrb3U05123xFfEZqIDdqPXbRI5gHwBd5RCc D1zy8bNfj610gmaZcmGVNyrIrBjckMrFQF+YNSueACoKQWdgSm+GXST7A60+qA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735318977; a=rsa-sha256; cv=none; b=ogkNdFkVFYUDuWmmRgeGLuxG3s5tYWsnVcKCA/RHaUUx8BfnNhfeeO8DDOqjnMjdF8iU+9 LVRFSyUuOZcKje/TsJiurAsw/eHyBPNCPMlIBoUJlthiS1Eq/KhOAvRPVLiVoQtliYqLr0 BKA2m17J93Hp5A7UuvowwmoYyJECBdjmv0YtaWk/Wk342otiD6T17w6HD/C6Fw5Duhzfaq Bkj4OcgeAydeS6lEr/OOkTKktQTGnYQLrEdwxvaOjD0lKLQVF0Gaoz54RfJJ9QxgMZO3zQ BWXB8bplWn3lEA3gjmgHKqWVI6qZYYpBXaLgbKDYao65OrnVZGWI8jFwplJIRQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YKWyn0RRgznhR; Fri, 27 Dec 2024 17:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BRH2u5d035865; Fri, 27 Dec 2024 17:02:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BRH2ujJ035862; Fri, 27 Dec 2024 17:02:56 GMT (envelope-from git) Date: Fri, 27 Dec 2024 17:02:56 GMT Message-Id: <202412271702.4BRH2ujJ035862@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 6ea1ce222c7c - main - bhnd: Fix a few use after frees when releasing resources List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6ea1ce222c7ce2aeae7ecd3558c731cb8c05a37e Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=6ea1ce222c7ce2aeae7ecd3558c731cb8c05a37e commit 6ea1ce222c7ce2aeae7ecd3558c731cb8c05a37e Author: Gavin Atkinson AuthorDate: 2024-12-27 16:55:05 +0000 Commit: John Baldwin CommitDate: 2024-12-27 16:55:05 +0000 bhnd: Fix a few use after frees when releasing resources The resource list entry needs to be looked up using rman_get_* prior to releasing the resource. Fixes: 9dbf5b0e6876 new-bus: Remove the 'rid' and 'type' arguments from BUS_RELEASE_RESOURCE --- sys/dev/bhnd/bhndb/bhndb.c | 17 +++++++++-------- sys/dev/bhnd/cores/chipc/chipc.c | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/sys/dev/bhnd/bhndb/bhndb.c b/sys/dev/bhnd/bhndb/bhndb.c index eeff088ffdde..511beae0cc25 100644 --- a/sys/dev/bhnd/bhndb/bhndb.c +++ b/sys/dev/bhnd/bhndb/bhndb.c @@ -1037,7 +1037,7 @@ static int bhndb_release_resource(device_t dev, device_t child, struct resource *r) { struct bhndb_softc *sc; - struct resource_list_entry *rle; + struct resource_list_entry *rle = NULL; bool passthrough; int error; @@ -1058,16 +1058,17 @@ bhndb_release_resource(device_t dev, device_t child, struct resource *r) return (error); } + /* Check for resource list entry */ + if (!passthrough) + rle = resource_list_find(BUS_GET_RESOURCE_LIST(dev, child), + rman_get_type(r), rman_get_rid(r)); + if ((error = rman_release_resource(r))) return (error); - if (!passthrough) { - /* Clean resource list entry */ - rle = resource_list_find(BUS_GET_RESOURCE_LIST(dev, child), - rman_get_type(r), rman_get_rid(r)); - if (rle != NULL) - rle->res = NULL; - } + /* Clean resource list entry */ + if (rle != NULL) + rle->res = NULL; return (0); } diff --git a/sys/dev/bhnd/cores/chipc/chipc.c b/sys/dev/bhnd/cores/chipc/chipc.c index 010ebbbd6cb2..09ca4d8884e6 100644 --- a/sys/dev/bhnd/cores/chipc/chipc.c +++ b/sys/dev/bhnd/cores/chipc/chipc.c @@ -893,6 +893,10 @@ chipc_release_resource(device_t dev, device_t child, struct resource *r) if (cr == NULL) return (EINVAL); + /* Cache rle */ + rle = resource_list_find(BUS_GET_RESOURCE_LIST(dev, child), + rman_get_type(r), rman_get_rid(r)); + /* Deactivate resources */ error = bus_generic_rman_release_resource(dev, child, r); if (error != 0) @@ -902,8 +906,6 @@ chipc_release_resource(device_t dev, device_t child, struct resource *r) chipc_release_region(sc, cr, RF_ALLOCATED); /* Clear reference from the resource list entry if exists */ - rle = resource_list_find(BUS_GET_RESOURCE_LIST(dev, child), - rman_get_type(r), rman_get_rid(r)); if (rle != NULL) rle->res = NULL;