From nobody Thu May 23 06:00:45 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 4VlHbK5nKyz5HCmY; Thu, 23 May 2024 06:00:45 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VlHbK5DwQz4SSN; Thu, 23 May 2024 06:00:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716444045; 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=yygCUqVmMfRbAkXFmP8nw4bJcOXFAAnii0J0V+wLDDM=; b=NgmdRHJcWl54DqeeKVobmZA/e2f8l/lqokD7uOglFM9Wf916eTiTynfbWImwjmqlf2XTb6 NJzGloDQDzEhxjzZVeH6DGQZslihbCd2BfoJGFnCefBL4sVT9dJ2jKsiCSu5sPfAjor6vE 2XkUmqaHdIjNiI3YqxSJ6+IdLOLXjpeiLW71m0+F+XVCVnVk503ZE8jVKYg8f6+qrLvKpn QBL1NLSHcwBCFt30RxjU27sKZ03poP8hcw8wCBWi4zEBXRKgLRqmAKPW/m/SjLf66vMD0r 1owR5VA2nzPtt05a0E1VzS/JWB3/zMT8d8fFwKQbyFhAtlM+telSE6A3h7asdw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716444045; a=rsa-sha256; cv=none; b=ZWYLcskhxtg5I2GZmyc7NbK9mK3Lfp2Vi/Yw8X2sQ4fiNzypvbWm5nHSpXtrJAp+SO3po2 Yl+j7zzgvBSDIF66Sp+EcTbvSSF1aEkXEJM+qH9/+pcWueNDKqaQEEACimaAoPsWkCqP6q fxqRzjVk44pDuSaY9hFnXkVOMYWtscBVoqTUgQUlDOCAQrnocBZ3DE6cPRDfesMB8Svawx 023GdN7LJiqwo6NV1WdnlYFjn7gocC2apMK1ejkP/MAUaFViTcgZoVxc9Dzu10cmizczv3 rTPBPfnu92WzXjXUKgIY5Nm42qLLPt9yzpxeNa9JDvYmxAtRPlYuYQygXW0ziw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716444045; 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=yygCUqVmMfRbAkXFmP8nw4bJcOXFAAnii0J0V+wLDDM=; b=kSrlYtJI4kFoxsDH35+dMUpv4rZ5BYWsnSQ6HbofxDgrgILewl11CfULFNDaWvL1f+hBLu 9ociQhVFDvR0ghI3qbwQ/LXYLna8cj0NVF81lPs8hE3Y9wp894AHtXelHustex4q1wiaN9 vVNxmuYxOLJNyKFKV3F4AXZBxJIh7ble7TRwkzU6QMT3ntCp/IpiI/JopLXjYTJlMrp/ky QlgYP+gPAkw4rtVXiQUe3NNH9zkmIHaxMiUezOIb3s0fapV24+i+I3BUWA57qjTFhuUsMC s6JaP8TKqZZ0zJjb844JTPrCHqBfjheUp4JDt3w7mVVxQiLtO5eQ+T6mudlT/w== 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 4VlHbK4rNjzdGR; Thu, 23 May 2024 06:00:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44N60jIW094316; Thu, 23 May 2024 06:00:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44N60jWS094313; Thu, 23 May 2024 06:00:45 GMT (envelope-from git) Date: Thu, 23 May 2024 06:00:45 GMT Message-Id: <202405230600.44N60jWS094313@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mariusz Zaborski Subject: git: ea5a708625e5 - stable/14 - geli: allocate a UMA pool earlier 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: oshogbo X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ea5a708625e5b5c89333e3e3e9a48fe588f05361 Auto-Submitted: auto-generated The branch stable/14 has been updated by oshogbo: URL: https://cgit.FreeBSD.org/src/commit/?id=ea5a708625e5b5c89333e3e3e9a48fe588f05361 commit ea5a708625e5b5c89333e3e3e9a48fe588f05361 Author: Mariusz Zaborski AuthorDate: 2024-05-19 12:53:17 +0000 Commit: Mariusz Zaborski CommitDate: 2024-05-23 06:00:57 +0000 geli: allocate a UMA pool earlier The functions g_eli_init_uma and g_eli_fini_uma are used to trace the number of devices in GELI. There is an issue where the g_eli_create function may fail before g_eli_init_uma is called, however g_eli_fini_uma is still executed in the fail path. This can incorrectly decrease the device count to zero, potentially leading to the UMA pool being freed. Accessing the device after the pool has been freed causes a system panic. This commit resolves the issue by ensuring devices count is increassed eariler. PR: 278828 Reported by: Andre Albsmeier Reviewed by: asomers MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D45225 (cherry picked from commit 4b3141f5d5373989598f9447ab5a9f87e2d1c9fb) --- sys/geom/eli/g_eli.c | 4 +++- tests/sys/geom/class/eli/attach_test.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c index 400734c10596..bed0875283aa 100644 --- a/sys/geom/eli/g_eli.c +++ b/sys/geom/eli/g_eli.c @@ -1047,10 +1047,12 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, bioq_init(&sc->sc_queue); mtx_init(&sc->sc_queue_mtx, "geli:queue", NULL, MTX_DEF); mtx_init(&sc->sc_ekeys_lock, "geli:ekeys", NULL, MTX_DEF); + g_eli_init_uma(); pp = NULL; cp = g_new_consumer(gp); cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; + error = g_attach(cp, bpp); if (error != 0) { if (req != NULL) { @@ -1093,7 +1095,6 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, if (threads == 0) threads = mp_ncpus; sc->sc_cpubind = (mp_ncpus > 1 && threads == mp_ncpus); - g_eli_init_uma(); for (i = 0; i < threads; i++) { if (g_eli_cpu_is_disabled(i)) { G_ELI_DEBUG(1, "%s: CPU %u disabled, skipping.", @@ -1165,6 +1166,7 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, sc->sc_crypto == G_ELI_CRYPTO_SW_ACCEL ? "accelerated software" : sc->sc_crypto == G_ELI_CRYPTO_SW ? "software" : "hardware"); return (gp); + failed: mtx_lock(&sc->sc_queue_mtx); sc->sc_flags |= G_ELI_FLAG_DESTROY; diff --git a/tests/sys/geom/class/eli/attach_test.sh b/tests/sys/geom/class/eli/attach_test.sh index bdb39a806fca..8803fa9f1a40 100644 --- a/tests/sys/geom/class/eli/attach_test.sh +++ b/tests/sys/geom/class/eli/attach_test.sh @@ -39,6 +39,34 @@ attach_d_cleanup() geli_test_cleanup } +atf_test_case atach_multiple_fails cleanup +attach_multiple_fails_head() +{ + atf_set "descr" "test multiple failed attach of geli provider" + atf_set "require.user" "root" +} +attach_multiple_fails_body() +{ + geli_test_setup + + sectors=1000 + attach_md md -t malloc -s `expr $sectors + 1` + atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none + + atf_check geli init -B none -P -K keyfile ${md} + atf_check geli attach -d -p -k keyfile ${md} + + for i in $(jot 100); do + atf_check -s not-exit:0 -e ignore -- geli attach -d -p -k keyfile ${md} + done + atf_check -o ignore -- newfs ${md}.eli +} +attach_multiple_fails_cleanup() +{ + geli_test_cleanup +} + + atf_test_case attach_r cleanup attach_r_head() { @@ -125,5 +153,6 @@ atf_init_test_cases() atf_add_test_case attach_d atf_add_test_case attach_r atf_add_test_case attach_multiple + atf_add_test_case attach_multiple_fails atf_add_test_case nokey }