From nobody Tue Aug 09 19:56:31 2022 X-Original-To: dev-commits-src-main@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 4M2P334B7Kz3j7JV; Tue, 9 Aug 2022 19:56:31 +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 4M2P333k03z3fDJ; Tue, 9 Aug 2022 19:56:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660074991; 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=5hgKi5IqnkywKDesH5jREwYfThh09PXpEG9SRbKHuDE=; b=CF9Y9ycK3PdaBQrgdRcyt+poH2rm9UQxo11IoEzSwuIwV1Gy/Cf2cNXc+SiJq1qIRkT956 HeM95HYFnb84h3wLTD9lgPCsnZ6370jKNdpgbcJDP/N7Pg7YHqsACxLA6LKQDfEpww9jVs Es4coYGmuLvXxcbt0cIxbAqRl7Kpx+KkGmuc0lp25NJEjdJNXun120UuKJzOIN+pRYBymL dKZPzgLXxczE4qZ0ruqOMFLS66LJ62bE8FiEChBKFv4jODHqzL8CBTXZxRweIA5wA/hMf5 uz2crH0VsQ+V4/NLr4QPguyEdX0I4GdEfuH6Fgz2RIfgKRnb9sNvaPtQwugYMA== 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 4M2P332lPmzkJS; Tue, 9 Aug 2022 19:56:31 +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 279JuVq7020769; Tue, 9 Aug 2022 19:56:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 279JuVVt020768; Tue, 9 Aug 2022 19:56:31 GMT (envelope-from git) Date: Tue, 9 Aug 2022 19:56:31 GMT Message-Id: <202208091956.279JuVVt020768@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 00d17cf342cd - main - elf_note_prpsinfo: handle more failures from proc_getargv() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 00d17cf342cd9f4f8fd1dcd79c8caec359145532 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660074991; 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=5hgKi5IqnkywKDesH5jREwYfThh09PXpEG9SRbKHuDE=; b=UtvrBj/9HS5AONpIZ4AANs0e7Re6GeY87ic5zFdXXiyXqikq1niIpunxXjW4ZTsY3y+3m/ hMKJTyqDdoDtkKio9g3onbGpQ8fR626nveTd6PA27Qomp+w6WBSwBum5dOqzxexCv5njkq t6L3/b9uRVEcTCR3dHYfO+THmzQwRlus5XOcBtIWR1oi0t2wMRAFfNmXxYq+oU7NLIWudJ M2EWg7j1evjhnf/Z367vfnGVaFmeJNpkMQP8uDs2XYglEjGKMGQSMorW+gYgz6bVEwuCcc 0R7mmlZfvPwPFTzoAHShYcFPQhn4jx+Fh38OllJVvclvuzGyYu2gqh6t6zUwRA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660074991; a=rsa-sha256; cv=none; b=nGtfZ+3eFDG/VrT0p6uy5d1ZbGW7zlpy6kZ6nat7ONGXLU70PcaagBmm+QnvPBAf1cTbEo b4b5LGEAn05+poDli78Q6mb725tuLeyAD23JgspAMSXH6R/lZIx/rCoPzsMbcZLbKxhBpm 9pmV/ACh61CDjtLxyUgOSl7i5bypfCJNOp5hrDxBhoF9L5xpiPy/ZN4Y9Enb+/OXVEyMEQ j/+E4U+4qz2TiLUbITTYNl7bO9wwlwRq+IF0yWkeFcXcEOW727VuWT2P7H2RldePaopfh9 s1VsQ/29JcLP8cpxb+hK6D2WXnbwvEsA9KP9/ZCFNk72IJk2J5ETtJi222vVOg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=00d17cf342cd9f4f8fd1dcd79c8caec359145532 commit 00d17cf342cd9f4f8fd1dcd79c8caec359145532 Author: Konstantin Belousov AuthorDate: 2022-06-03 08:21:23 +0000 Commit: Mark Johnston CommitDate: 2022-08-09 19:44:45 +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 --- sys/compat/linux/linux_elf.c | 9 ++++++--- sys/kern/imgact_elf.c | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/sys/compat/linux/linux_elf.c b/sys/compat/linux/linux_elf.c index bcbd4d1cad51..b02b6e2cc777 100644 --- a/sys/compat/linux/linux_elf.c +++ b/sys/compat/linux/linux_elf.c @@ -155,13 +155,16 @@ __linuxN(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) + if (sbuf_finish(&sbarg) == 0) { len = sbuf_len(&sbarg) - 1; - else + 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 { diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index ca4c59089775..38be7d100ae9 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2205,13 +2205,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 {