From nobody Tue Aug 09 19:56:50 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 4M2P3Q3dHwz3j7X4; Tue, 9 Aug 2022 19:56:50 +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 4M2P3Q34N6z3gCD; Tue, 9 Aug 2022 19:56:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660075010; 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=eNVUdOpZrnxq0vfYvCQt+VqmNdOStOu39PXq85rHEPg=; b=c59dqcVgJdFXsoCbnHJew14jP7QcBOKktBrW9Sxca/0z3jGAop5ID8QSdrpgSKHz6ZZWja EG286r+atqNTnbI3rguWl5E6NDgUIkKExhF8Q/ksgIfI4NUrY4lCusrFzFln12CS/TNRNm qLCA4yUbVn/NpGPgmO1/+IKDpy0NOQuP6YspT23VqLg5DYE38xnrbSiWOClc3iPHUVHRjp Um96/l1rhFSD7ZzcJDsvbTfYzFig/47nMC3ISbQhGrQ9pH7fBcD0yFVX5TBwQUrQLC6vyA 9Y/JpEhuc4XBEPmIgQPDEtVv8BY5w60MxOsu2DHSJh0Ee+FBVaBspFjLdacpzA== 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 4M2P3Q29GLzkJV; Tue, 9 Aug 2022 19:56:50 +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 279JuoPL021082; Tue, 9 Aug 2022 19:56:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 279JuosD021081; Tue, 9 Aug 2022 19:56:50 GMT (envelope-from git) Date: Tue, 9 Aug 2022 19:56:50 GMT Message-Id: <202208091956.279JuosD021081@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 2170511d491b - stable/12 - elf_note_prpsinfo: handle more failures from proc_getargv() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 2170511d491b65a07dc4416ecda2fbb37349aa10 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660075010; 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=eNVUdOpZrnxq0vfYvCQt+VqmNdOStOu39PXq85rHEPg=; b=f8RTtt4kV4P0sRv70M1ICoCNqy8HUPjONLhvlndzfrWJUQnk7iRiKsULgJPkRIKSaLWHMb ehdKLR/ra/Nab8c49LFagqOjNQQM24waLQS6RatcB8T1qFBjqwmDeZJa1vvW6+twlovj5v SF98lZaod74NaCNNhYDTJelSqNh6bT6L2yUH9NQ9K/EOzbGH8Ly/8dux6zxGTC7c9/RzDV fx/ZimBqibQ8r/KF4DvDSXsLWcI15Kdu+cmGmKTlsf6mwNfRYPGG6ayCMzRD+I9o7ykuoM AqoJCI4dGrzKmJNkvAjHcPG9CvBHZ24h5awN81Go+CQUmeIhr/VUbotG/p4uqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660075010; a=rsa-sha256; cv=none; b=W27smTdfzqpNrAC9lfKOCCLl0lVNsQtLObaO/yn8K4146mIZIV0NizyA1Goqru940spQek D4I+M7ITpWQ++wd8SBZFucBauLO6HRqESpv8q9lZXknpmYadx4wY8lV5dFWZUEWT75JQ+l 2W0eDQR5Li1Vk/4OGpHbuqxsTXt6rwqbz9i5B3582CIhYApiNiTjq3w6bc5lxur9J8qCTA lS20ZYpFLkQVPIWa6ybc3E0rwTGWIFwrEYkwzy/kc0VGoK7M/SqR2oWV4w9aq15BWPp8do /AnoJrsRi2Iwkr9890OY0jz+i4/Ir95may5ofbCv4H5ABo7z/xN5uGW1TKCioQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2170511d491b65a07dc4416ecda2fbb37349aa10 commit 2170511d491b65a07dc4416ecda2fbb37349aa10 Author: Konstantin Belousov AuthorDate: 2022-06-03 08:21:23 +0000 Commit: Mark Johnston CommitDate: 2022-08-09 19:46:28 +0000 elf_note_prpsinfo: handle more failures from proc_getargv() Resulting sbuf_len() from proc_getargv() might return 0 if user mangled ps_strings enough. Also, sbuf_len() API contract is to return -1 if the buffer overflowed. The later should not occur because get_ps_strings() checks for catenated length, but check for this subtle detail explicitly as well to be more resilent. The end result is that p_comm is used in this situations. Approved by: so Security: FreeBSD-SA-22:09.elf Reported by: Josef 'Jeff' Sipek Reviewed by: delphij, markj admbugs: 988 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35391 (cherry picked from commit 00d17cf342cd9f4f8fd1dcd79c8caec359145532) --- sys/kern/imgact_elf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index c056cfcec8e0..dba87d2853ca 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2149,13 +2149,16 @@ __elfN(note_prpsinfo)(void *arg, struct sbuf *sb, size_t *sizep) sizeof(psinfo->pr_psargs), SBUF_FIXEDLEN); error = proc_getargv(curthread, p, &sbarg); PRELE(p); - if (sbuf_finish(&sbarg) == 0) - len = sbuf_len(&sbarg) - 1; - else + if (sbuf_finish(&sbarg) == 0) { + len = sbuf_len(&sbarg); + if (len > 0) + len--; + } else { len = sizeof(psinfo->pr_psargs) - 1; + } sbuf_delete(&sbarg); } - if (error || len == 0) + if (error != 0 || len == 0 || (ssize_t)len == -1) strlcpy(psinfo->pr_psargs, p->p_comm, sizeof(psinfo->pr_psargs)); else {