From nobody Thu Jul 07 18:13:53 2022 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 E83708D5C22; Thu, 7 Jul 2022 18:13:53 +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 4Lf4Ks67Hsz3rN5; Thu, 7 Jul 2022 18:13:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657217633; 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=X+YHW6VIruQHQClc797gYmr1V2A4PYyIuMurYwhIsUw=; b=cy2too+NF+w0O3+/evmHNH2zpQjqzTCwDcCju/H9haz/ibL42UsEhCu2lvrqztLvyjMnQ1 JUh7nVRRoiJVaEDzGw608oFjnqcEtB+bSlw9EscM1oQkAge7P5Q+Kj//VZNHeXl6+HURv5 ebYjuJ8uHYWXuIrCXBM7EMgZqNs92COVZLxeW5IWtwNXFuOxDM7ofYju7txIOgWRXyrja8 yNdbJa2PqPxsS4uHBaqVQwuKxUhubD/NodGbU/emj4G8akZ+sLFmrbhdfGx9WRRX9T/bL3 iGSsJSmdPHPDiNCE8PQeKyupiQeYE4n+QRvZywNQQhJpcQr8DIMb4yufEh1k8A== 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 4Lf4Ks58F0zs61; Thu, 7 Jul 2022 18:13:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 267IDr60038380; Thu, 7 Jul 2022 18:13:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 267IDrkS038379; Thu, 7 Jul 2022 18:13:53 GMT (envelope-from git) Date: Thu, 7 Jul 2022 18:13:53 GMT Message-Id: <202207071813.267IDrkS038379@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: a6bc861c2090 - stable/13 - rc.subr: use _pidcmd to determine pid for protect 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a6bc861c2090e6f1b52c930d27df340efd1f0a74 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657217633; 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=X+YHW6VIruQHQClc797gYmr1V2A4PYyIuMurYwhIsUw=; b=r+5CFg4PPDr437mPPJMJwGkljSiYbCRQtFoVzI441Z+UBKQ39RP2p0jl4NR1UYeBiPDQOl Sj+oPdIqaajPgolbg36nopyE/NbX75MeEQKSybXwTeschMWx5MjiZ51dMNJYNrNHry7ZTY i89h2mME6yXcDzKyW3WifIFNQ63iBVVUgO5QaJndBtF747f3IjsL/hfKBEDYSgIqvDpT74 Y8wrYQiHV9PSBtkULk9wdG92D90Zf5mVAx0Z6wQ7ddmVwI7BAX7ZNX9QZqx5sjLTGP3GgH 4AO+Aw0i5HN8GBPSX/K5+A1WIPDFndoFSZEHW97pF5s+/JavzGfKzvHOLtb2ww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657217633; a=rsa-sha256; cv=none; b=Yn/+nAZ77Z/3DrBSG/WcHYlV11pmPKtNF7XnCrzp1gM2asdX7Mk9rI0aBJ2aoLWrNVMJzi s2MQoOrtUafpawGlMKO4yv6KOMHg0Z0KCh5YORzXpNUPFVIFHAVJHx6pVf89ZcjuMDh9LP lFgs4/HKH8ZSN+wTtL8i8cVOWGDefU0OKjYc8B92b7ZtqU4F1kTSN+OJUt+O049s0e8fhZ fNyWijGC9gCWSVRZJFxvkedhC+jDYkyOxSzOJd4ZUJ2hOy/6BrwdFIQSQ7c8ssyFwotAee O4rjkYbGhXKdCYrYklw7BnpbA2kAv9euMrw+Y1bqKjib7lMjgiGggief/jNsdA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=a6bc861c2090e6f1b52c930d27df340efd1f0a74 commit a6bc861c2090e6f1b52c930d27df340efd1f0a74 Author: Mariusz Zaborski AuthorDate: 2021-06-24 18:14:31 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2022-07-07 18:12:09 +0000 rc.subr: use _pidcmd to determine pid for protect This is a more reliable method that accounts for existing pidfiles, procname and interpreter settings. Current method of obtaining the pid for oomprotect="YES"|"ALL" processes in certain cases fails to find a unique pid. One such case are rc.d scripts defining command as: command="daemon" which results in all processes started via daemon being selected and passed to protect(1) which fails and prints usage: $ /etc/rc.d/exampled restart Stopping exampled. Starting exampled. usage: protect [-i] command protect [-cdi] -g pgrp | -p pid Running the same with -x reveals what happens: + pid='3051 4268 4390 4421 4427 4470 4588 4733 4740 4870 4949 4954 4979 5835 5866 55487 55583 56525 57643 57789 57882 58072 58167 99419' + /usr/bin/protect -p 3051 4268 4390 4421 4427 4470 4588 4733 4740 4870 4949 4954 4979 5835 5866 55487 55583 56525 57643 57789 57882 58072 58167 99419 usage: protect [-i] command protect [-cdi] -g pgrp | -p pid We have a more reliable way of obtaining pid already defined in rc.subr and available when protect(1) needs it. We can simply `eval $_pidcmd` which also invokes `check_process` but properly accounts for existing pidfile, procname and interpreter settings. With the change the pidfile is properly obtained. Submitted by: Adam Wolk Sponsored by: Fudo Security Differential Revision: https://reviews.freebsd.org/D30367 Approved by: oshogbo (cherry picked from commit 6ba108e52d175b6833437c8627ae5d0546a4e102) --- libexec/rc/rc.subr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index e859ae06962f..b027fa5facf4 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -1272,13 +1272,13 @@ $command $rc_flags $command_args" # We cannot use protect(1) inside jails. if [ -n "$_oomprotect" ] && [ -f "${PROTECT}" ] && [ "$(sysctl -n security.jail.jailed)" -eq 0 ]; then - pid=$(check_process $command) + [ -z "${rc_pid}" ] && eval $_pidcmd case $_oomprotect in [Aa][Ll][Ll]) - ${PROTECT} -i -p ${pid} + ${PROTECT} -i -p ${rc_pid} ;; [Yy][Ee][Ss]) - ${PROTECT} -p ${pid} + ${PROTECT} -p ${rc_pid} ;; esac fi