From nobody Tue Aug 09 20:00:28 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 4M2P7c4gJ1z3j8Gb; Tue, 9 Aug 2022 20:00:28 +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 4M2P7c3fjwz3jtV; Tue, 9 Aug 2022 20:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660075228; 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=r1Tj0ALKb7aCyEk2RhioxUQ5WyTyNC6EigyO7Sjh5rw=; b=qIdFuXwqkYzSgJEzi+r8XEl2OMqrkLNCYwgdEZq6r9XlV/hkNDJc9hI/jtvVeVk8hqlPZ/ 51L7l6P9Dlqlquh6mKPoVmogGGKDSbp3SNQYHVeQQw+NrdTPeHnZW5GnvxX48ukHPbQk4W ORl576baCLr4tHubxAIqX94aDE4kEp1i9KvzbYzDIki19FAqwtJccoRMVmjFhSrDl19Xj3 LtOVCXWi10IYI25urYkCSu0MqVUnq9MfPjS8e1JoYA4o1YFnNtugUoJ7PbreGOIBYHta1o vKRz5LM4n+OhGUAIMw8e84zm+TDCc+hG73Av7+tTjmHxd3M1N3Ir3LoNdDeVrQ== 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 4M2P7c1vDbzkMM; Tue, 9 Aug 2022 20:00:28 +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 279K0SJH030989; Tue, 9 Aug 2022 20:00:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 279K0Sbe030988; Tue, 9 Aug 2022 20:00:28 GMT (envelope-from git) Date: Tue, 9 Aug 2022 20:00:28 GMT Message-Id: <202208092000.279K0Sbe030988@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: 056ffc74a769 - releng/13.0 - 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/releng/13.0 X-Git-Reftype: branch X-Git-Commit: 056ffc74a7693808c843e15d85deee20abf5c4e2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660075228; 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=r1Tj0ALKb7aCyEk2RhioxUQ5WyTyNC6EigyO7Sjh5rw=; b=aZAN/dTtE8S2ZMvf7z3+mFQGAQQzVDuqooKGcJlUYzo9uDx6hKiAkkwOkD1s5RyNy5nMZM 9veoRhRGB+wb0dADkT/cTbVGyqfhEuTvFTxxMiQG2WU1dRcaF5vXgKAGHXL7HhOOVol6rK ZrftV8T36sR8NpvZ1BF9+SJcxkv3CgwYWjwwLuCbm3CWu4byxEkhcnqd8MnFEiRTxL5vE8 MVk7Db7btPtWof2vkzQGHtZvty/uKP18URL8BXZ/ewrGCKFIKFps4WODNtZJpzaMXCH1c8 VheddrVe0vrslM+lIz1D4yQrA1RPcp4mGG+ZLQqm5Lu/EQ1ySDYOopAz46oHjA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660075228; a=rsa-sha256; cv=none; b=GZo391dMNtm/ObdqY/HRL19QaJdLXqu/cpePFaOsKoFvYS6kMWpfKKOs1Hdt9dWvMgoHdz c0dJgRt/YSNJoHLbPpoJXb1kFQTSwpA6499uqkP/sxos/LJvaVW+jPIg9mjXzZEgemc2R0 HSdnxFEHgfzoBg98yb+pz2ONlsnIvYayhkO/stqsmYO77KSWdvSs19AeLU4Qc9yff6ne3l 495htKEb0bKfQmpo7dfbU/kbMpAaoFQ88F6gTFKINs7dgABwOzOyBQjArEt7mfUnkJwVjC kPF0285VUseAQD/MVFb0ArLscH0d/vHzwo622cNBheiClmOrqV0o5xfGgJwzZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=056ffc74a7693808c843e15d85deee20abf5c4e2 commit 056ffc74a7693808c843e15d85deee20abf5c4e2 Author: Konstantin Belousov AuthorDate: 2022-06-03 08:21:23 +0000 Commit: Mark Johnston CommitDate: 2022-08-09 19:59:14 +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) (cherry picked from commit 8a44a2c644fc6d4ec1740fcc0b3ff01eac989ddf) --- 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 dae11ab92a6c..626a8a59c594 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2216,13 +2216,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 {