From nobody Tue Jun 14 16:01:12 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 3EC35831C42; Tue, 14 Jun 2022 16:01:13 +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 4LMtTN710Yz4v7Z; Tue, 14 Jun 2022 16:01:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655222473; 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=BX1LHVNHqFAFcPWgF7egM8CFYhJ4OmyDNmMbOya6QAI=; b=X5/yzjkoM4yyy03yLfIMmVXdyuhjXKmc1SvRNgoffwYYiB/52iHBRXWM/BORiKP650wJYx ozCfhE1A6VgzMgWknHbA8iGDvYAkgWb8/WaY/y/UEKBaxaYteP35PpwumGk2y0m6CV45Oq kOIj5fP5+xiPKWxxwk+z0imWJUp/MuXeP/yRAVIJ4u4I8mfm1N77yOsQoNO/+l4TnATvzi k9cll+tcdI+vuOgnVe+EBqS6B6tbD3abrsBpg8tjh9nIdmz+hsiTNnxb7D6cnW/8+o8+0r C6XJq3GDcjL7kgGDiwR2z+HRoydTRSwNxm690vyqw7EHOE73WpmsAb0sCc3ZBg== 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 BDC975154; Tue, 14 Jun 2022 16:01:12 +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 25EG1CFI082601; Tue, 14 Jun 2022 16:01:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25EG1Cid082600; Tue, 14 Jun 2022 16:01:12 GMT (envelope-from git) Date: Tue, 14 Jun 2022 16:01:12 GMT Message-Id: <202206141601.25EG1Cid082600@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: 4b0c6fa0dcea - main - truss: Make control message header parsing more robust 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: 4b0c6fa0dceac797f43dffd5642c1aed727c6ea6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655222473; 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=BX1LHVNHqFAFcPWgF7egM8CFYhJ4OmyDNmMbOya6QAI=; b=UxEahX66ufpdCKNjpV2D0fBLI6yUVm1u28yyf+6oRqnVu9JfkGzh6NsL8wrsSMWV0y2Iop iNwa+OMnxIR4ME4ZDME3cKRhJE/xAemudaS+W60WO9usNzHoKPyTfNjaDvzs1LXLsRarVC +D08yqaln/L6VxENGA4E4uekRsvdjSKd3vp2Wf8AKtTktT5iS+of2gdnW+vEuk3Eg5Si40 Cu/ZG6Ha1tyBLVB/AB5T0F3HlT76PeKjkUlQ0QneAC0r+9xgkW1j+JB+HdrJqBfhM2m408 YpWmB+yyS2QFo6RPALe3GVdCqoDQLZwkfT2RBjw4AIRSVsQGD/RsBOo7xpn6UQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655222473; a=rsa-sha256; cv=none; b=BtnybniuVuRSwE5uKWzE7cWpq74XM5x7qyYnahT7ShkvwUJCswP3LcUZVeZ2y+U64nkyET rSSdB+jBw33JjEs8riLcJ8gOpKcXPuUnDeL4c02gGnxh0adJUnPeMFF62GeFq3H5I22oj8 wjfy2vBYXPaEI0gZDXZVkOtH5en2GoqW1fIwXahP+p0zr4kJq5hDJHCK2FiT1hyBXxhyqk l0eEXAGv8cBUhUyS3gxH70aqNofbxBJGLZws5G2zP0qngLk+wl1xao/wNFssPxZTVXuMgH tGAeZXzPRstTwagjHcIWgLUR2aRkQP3SeZ7A7GenaQv8aUedqlegreeFOKl63Q== 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=4b0c6fa0dceac797f43dffd5642c1aed727c6ea6 commit 4b0c6fa0dceac797f43dffd5642c1aed727c6ea6 Author: Mark Johnston AuthorDate: 2022-06-14 15:34:57 +0000 Commit: Mark Johnston CommitDate: 2022-06-14 16:00:59 +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 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35476 --- 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 171bed54edb0..0a3f616294af 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -1480,6 +1480,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;