From nobody Wed Jun 29 14:40: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 A7DDD86D915; Wed, 29 Jun 2022 14:40: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 4LY3zn2Zdyz4hSr; Wed, 29 Jun 2022 14:40:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656513653; 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=37FLrkJcJ+3N2zi7ulzjk96CEuirip20+WwqlbPlFcE=; b=E4Eb3oF3iA0XMAda6iv+zt6ia4Pik0k6Q/jmv4l0v/BLXqH2eX6RqVstykPLPqoqWccBuZ zIn2rwGIA1PWSLsCOPKmIjNExBNTT6dZJwUQ1OtMRYnzWmSf4WdEYgVy9r8aYoO/FLPI2U 4AkR3SZUTcqIGss2E0GFRR0hx7WuoCXX89XBNnL3+OxeeUmKlWLJxjqTuZ6YSDZfcN3pET F5hhecjVQwWxPOPPMvH9MbaQCcVmSZezGKY0A1ui8kiOQlEgIwlTWh6Z2F2yt7mSg8/MWK iYvohj+lLfK80NQ0nSfJhvRNXF4S1BsSdD+KsniZDzl1XFpzotogWvAJXcUUWQ== 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 1457713959; Wed, 29 Jun 2022 14:40: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 25TEer2V031661; Wed, 29 Jun 2022 14:40:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25TEerKg031660; Wed, 29 Jun 2022 14:40:53 GMT (envelope-from git) Date: Wed, 29 Jun 2022 14:40:53 GMT Message-Id: <202206291440.25TEerKg031660@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: 3d81c26f92e1 - stable/13 - truss: Make control message header parsing more robust 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/13 X-Git-Reftype: branch X-Git-Commit: 3d81c26f92e14db25dcc6046af1493c0d5a75443 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656513653; 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=37FLrkJcJ+3N2zi7ulzjk96CEuirip20+WwqlbPlFcE=; b=VPml2uJjaUynK8PP3Gy4a6cRxEdgsbEjV9TmWAaj79RSQZ+Kb9sN9tikCrGSnyNq793PbX GJv2fXTZ/cRB1yu0Ig/2kvmweBPck0gAJP4fQN0Y7U3mfmMXp6j61mh9LxOWsYgCRXuKWA h6SreUTLJ1gzxOfmMgPXycuHyOnmb4FblJFhwaQIphD1ODp4/SCjZSX1LhA5n6bC478CNO xsqravh3akRqggZUVVMATf9CwnqJ7GPVYAZxE+VC5YYfrLsKt86Kf9Y45O3XKswVo84zh/ HwL3LCJK1V9jVm8Qu74lI+0F+D0VKMQ/LaDq8Z1Z/HWs3Jv7EINmdrxrJEmIuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656513653; a=rsa-sha256; cv=none; b=CRZlWCCqu2/blQcMCagN53m3rIReqgK4MZrR9H+yN2BPYTC1eMPrUZAhPwUg4naYM6JxtJ +Oss+Mq1ZeG5Ca4F31/xnvoYbOadrZnRWvD5XQs+pu8JMirt72UtHEiGbsKs3oxAT12346 eFdxBojW2dBy5j/HDeKc/sjIhHwhuMgXaBBq26x/6p99ufZAtldt/V/RXT8kBs/S5dolEZ rhc1OUk5BIWNRwFoQUgi9QxEb7ZMDUbJrqyh3yuXKEO2jZqd++r64QWRKfrD+YYhkn681U 1nuCncL5zjcJxu99scOAphaCI0L9Y8RntJoBOVhlLWSdGWHpVqvJPCcUM4V5eQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3d81c26f92e14db25dcc6046af1493c0d5a75443 commit 3d81c26f92e14db25dcc6046af1493c0d5a75443 Author: Mark Johnston AuthorDate: 2022-06-14 15:34:57 +0000 Commit: Mark Johnston CommitDate: 2022-06-29 14:12:33 +0000 truss: Make control message header parsing more robust print_cmsg() was assuming that the control message chain is well-formed, but that isn't necessarily the case for sendmsg(2). In particular, if cmsg_len is zero, print_cmsg() will loop forever. Check for truncated headers and try to recover if possible. Reviewed by: tuexen Sponsored by: The FreeBSD Foundation (cherry picked from commit 4b0c6fa0dceac797f43dffd5642c1aed727c6ea6) --- usr.bin/truss/syscalls.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 06e984de3fe8..cf863d2bfaaa 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -1663,6 +1663,16 @@ print_cmsgs(FILE *fp, pid_t pid, bool receive, struct msghdr *msghdr) for (cmsghdr = CMSG_FIRSTHDR(msghdr); cmsghdr != NULL; cmsghdr = CMSG_NXTHDR(msghdr, cmsghdr)) { + if (cmsghdr->cmsg_len < sizeof(*cmsghdr)) { + fprintf(fp, "{}", + cmsghdr->cmsg_len); + if (cmsghdr->cmsg_len == 0) { + /* Avoid looping forever. */ + break; + } + continue; + } + level = cmsghdr->cmsg_level; type = cmsghdr->cmsg_type; len = cmsghdr->cmsg_len;