From nobody Thu Mar 17 21:04:49 2022 X-Original-To: bugs@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 8BF181A1D16A for ; Thu, 17 Mar 2022 21:04:49 +0000 (UTC) (envelope-from bugzilla-noreply@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 4KKKQn27XYz3mn4 for ; Thu, 17 Mar 2022 21:04:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 2A435120BF for ; Thu, 17 Mar 2022 21:04:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 22HL4nfu039177 for ; Thu, 17 Mar 2022 21:04:49 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 22HL4nWD039176 for bugs@FreeBSD.org; Thu, 17 Mar 2022 21:04:49 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 262633] Missing mtx protecting variable prison->pr_prison_racct Date: Thu, 17 Mar 2022 21:04:49 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: firk@cantconnect.ru X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647551089; 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=JJNV51cHncbGncg55Q4ECncGydulHg3myumO8Hmg+QY=; b=J/VD6OedR/6zzxKVRhbdOco51CQia0REdz7Cuiidx7OQ1RAxQ1LuPY4BCdEnm2xZgDcmm9 fqQkw1G8w34HrphIThMhCNfwTOwXD8vcSlr9UJQWWzxeSKBThAlfGMjB9eFreZiqz9ksLb lwPHhr+cn66sY9Za+bn3a4/HGEiHr2Gl8jLm2SnD355CX+8Z3d1ZUWWcSnNCZ8IbnGckuw qa+06iUCurpjhESw/4TkITqUWDaLBgDicIhrmAVm37+thsF7zPToly2blSGP9BVho6oNba Uvhx+zW3XuWnAGq5pFJ1KxO2dLkLllA1yzi1k/ns65Qr9LX/Ca+H3Hmrgq1Quw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647551089; a=rsa-sha256; cv=none; b=rzn7ThUTjBHqzZsLhcJv2OrGQvoRIwA2Rt6Ns2Xu41d2hkmCh25FFaolzsGOp2wjeToLTF apdaq/Zg//qtRbINDA2Dz1Z46vEpZGPWQgHoXmC1mXA2vc+TCSRNAs9tRQqdESALUWBv5u 7YRH+/DN+V6gMbjVtnV8wTMEdhqvqLA1oU9OG+1IeDyhR2K8E3bA4/VfK1gdLei3AsUt4N /u6hB3AMQo769DUIgd9Homdd0rnI2R0oHwFssb1TD/8OeLbT1esUrb1ajVXA+fovJwMtRE WZ9tZSLp/bBJXjOs5SRsjhdpxooxRK/cEzGH/uYQ8V136Z8K86T6QlbN5OtP1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D262633 Bug ID: 262633 Summary: Missing mtx protecting variable prison->pr_prison_racct Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: firk@cantconnect.ru jail.h says: > struct prison_racct *pr_prison_racct; /* (c) racct jail proxy */ > * (c) set only during creation before the structure is shared, no mutex > * required to read This is not true, there is kern_jail.c/jail_racct_modify() function which c= an alter this field in runtime. Renaming jails is very rare case, and it usual= ly is not available to any non-toplevel-root processes, but it is still possib= le. While all the above was just a theory (but I don't know all possible practi= cal consequences), there is at least one case that may lead to panic. Let's see: > jail_racct_modify() { > // ... > pr->pr_prison_racct =3D NULL; > prison_racct_attach(pr) { > sx_assert(&allprison_lock, SA_XLOCKED); > prr =3D prison_racct_find_locked(pr->pr_name) { > // ... > LIST_FOREACH(prr, &allprison_racct, prr_next) { > if (strcmp(name, prr->prr_name) !=3D 0) continue; > prison_racct_hold(prr); > return (prr); > } > prr =3D malloc(sizeof(*prr), M_PRISON_RACCT, M_ZERO | M_WAITO= K); > // ... > } > pr->pr_prison_racct =3D prr; > } This LIST_FOREACH may be time-consuming if we have many prison names already registered. Also, there is malloc(M_WAITOK) after it. All this time pr_prison_racct is NULL, while, for example, racct_add_cred_locked() walks through pr->pr_prison_racct->prr_racct without any prison-related locks and may dereference this NULL. I'll try to make test program for this later. --=20 You are receiving this mail because: You are the assignee for the bug.=