From nobody Fri Jun 17 19:41:39 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 5A84685E0C0; Fri, 17 Jun 2022 19:41:41 +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 4LPqDN4LJgz3jHM; Fri, 17 Jun 2022 19:41:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494901; 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=Ka/UlUJkU8GgaQxYRI7hoDuTv0ZNEjbFcRjorRjlseU=; b=NoF7sYgOqtXN3Z5W0RjVe1H81YtH9d89ZOvhVQ7BXmx31szOElwW5QOGfSs0C3P2Y8jexG 7X7Id6Hn4KjqMgVnLCLtVN9Yqc+Ig/GGKji0Cem5akyPSfC4qX52ONLbLvQu1XUTflxMBx Ll9c9HTjsMMhFJ/xbwTUUmhumFDICEihew0Pk8XQscQAAmts1I59siJy/Kdct30xzEcXW/ h9NJQ1NZJZEJ9/ipaxzQmOhr6N6i3CiszFg1Mq4t3OBp9F17YUM+lg5kI25ETQK5ykdlXt B1QTJL6hRFdb5rdGA5Fz3B3FoXTNn0LgSdTeSAoRsA3V9580jgRr0oik2T1stQ== 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 D087025E0D; Fri, 17 Jun 2022 19:41:39 +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 25HJfdHJ031636; Fri, 17 Jun 2022 19:41:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJfdKF031635; Fri, 17 Jun 2022 19:41:39 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:41:39 GMT Message-Id: <202206171941.25HJfdKF031635@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: e4aabaaa3dad - stable/13 - vfs: Consistently validate AT_* flags in kern_* functions. 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e4aabaaa3dad6bfef0a1941c9c501be7d325080a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494901; 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=Ka/UlUJkU8GgaQxYRI7hoDuTv0ZNEjbFcRjorRjlseU=; b=EhD5ylqSTizm4d6NIp2gbyH48wspHn3jDusX+IXh21N/O7oDdO1oNwStsVCas93kG8kRhZ naM30Wkv2A6HsM5+FF9wHjRgnC/vT9gHlLdCbftrWEloMhrvRYBX/4DdbWNc7AyZYMa3pM zye/hNkhpOaF1veXuSXd7CRFO1X/JYW06mQ10Vwa1nxMRmukXnj3Lrws5D9mG1ZuAHh3RB awUszRpcKnVaNBo76vAKVhESmAous23iZFYo6wbiUj6Gf33OtSC9QGpCg4nfQFkP3RSq0P rS/uA+RHcR+IeyrrMI8wNPP17S/ruNangOU3RYXCDeAe9OFfRYM88rmh5z+phQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494901; a=rsa-sha256; cv=none; b=Q1nEK8XEZP8ookzxgTLhyEXjWqyBt6/rviuGbmRPRUeCXB3Lea5TGZE+Ny1ywVx3qouCxV /d1JM71dSNSBo1QTAUikQVMsLZS8rO2HZ97cWmlV3mMotA2Bglt8r+kJlthtmo3VX6l/bV h+vLXAqNiZqIWy8nhW+ezasG2Re3/NLba/p2MhpX1HNEULS8b7ZrzRPMAz4DcIiwXIBdHU Abu5deV/H24LWrmdGbL7e/t01zGt+3VTwHhL6+ZmBvbgO6lNoCtXCUA/fs0nlhjSoOF4ma jLyuLI2Ys82WzXFhKx5UEN+ejHaxM08+cfSnSpyhKvDydAWGiAHgrP//y22cyQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=e4aabaaa3dad6bfef0a1941c9c501be7d325080a commit e4aabaaa3dad6bfef0a1941c9c501be7d325080a Author: John Baldwin AuthorDate: 2021-11-09 17:42:12 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:35:42 +0000 vfs: Consistently validate AT_* flags in kern_* functions. Some syscalls checked for invalid AT_* flags in sys_* and others in kern_*. Reviewed by: kib Obtained from: CheriBSD Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D32864 (cherry picked from commit 57093f9366b7eeb48054ff2fa77b9d01d2b3cfc2) --- sys/kern/vfs_syscalls.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 64ff9b55c57e..3b3947b2ccb7 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1523,15 +1523,9 @@ struct linkat_args { int sys_linkat(struct thread *td, struct linkat_args *uap) { - int flag; - - flag = uap->flag; - if ((flag & ~(AT_SYMLINK_FOLLOW | AT_RESOLVE_BENEATH | - AT_EMPTY_PATH)) != 0) - return (EINVAL); return (kern_linkat(td, uap->fd1, uap->fd2, uap->path1, uap->path2, - UIO_USERSPACE, flag)); + UIO_USERSPACE, uap->flag)); } int hardlink_check_uid = 0; @@ -1580,6 +1574,10 @@ kern_linkat(struct thread *td, int fd1, int fd2, const char *path1, struct nameidata nd; int error; + if ((flag & ~(AT_SYMLINK_FOLLOW | AT_RESOLVE_BENEATH | + AT_EMPTY_PATH)) != 0) + return (EINVAL); + NDPREINIT(&nd); do { bwillwrite(); @@ -2757,10 +2755,6 @@ int sys_chflagsat(struct thread *td, struct chflagsat_args *uap) { - if ((uap->atflag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | - AT_EMPTY_PATH)) != 0) - return (EINVAL); - return (kern_chflagsat(td, uap->fd, uap->path, UIO_USERSPACE, uap->flags, uap->atflag)); } @@ -2789,6 +2783,10 @@ kern_chflagsat(struct thread *td, int fd, const char *path, struct nameidata nd; int error; + if ((atflag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | + AT_EMPTY_PATH)) != 0) + return (EINVAL); + AUDIT_ARG_FFLAGS(flags); NDINIT_ATRIGHTS(&nd, LOOKUP, at2cnpflags(atflag, AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | AT_EMPTY_PATH) | AUDITVNODE1, pathseg, path, @@ -2888,10 +2886,6 @@ int sys_fchmodat(struct thread *td, struct fchmodat_args *uap) { - if ((uap->flag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | - AT_EMPTY_PATH)) != 0) - return (EINVAL); - return (kern_fchmodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode, uap->flag)); } @@ -2920,6 +2914,10 @@ kern_fchmodat(struct thread *td, int fd, const char *path, struct nameidata nd; int error; + if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | + AT_EMPTY_PATH)) != 0) + return (EINVAL); + AUDIT_ARG_MODE(mode); NDINIT_ATRIGHTS(&nd, LOOKUP, at2cnpflags(flag, AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | AT_EMPTY_PATH) | AUDITVNODE1, pathseg, path, @@ -3017,10 +3015,6 @@ int sys_fchownat(struct thread *td, struct fchownat_args *uap) { - if ((uap->flag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | - AT_EMPTY_PATH)) != 0) - return (EINVAL); - return (kern_fchownat(td, uap->fd, uap->path, UIO_USERSPACE, uap->uid, uap->gid, uap->flag)); } @@ -3032,6 +3026,10 @@ kern_fchownat(struct thread *td, int fd, const char *path, struct nameidata nd; int error; + if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | + AT_EMPTY_PATH)) != 0) + return (EINVAL); + AUDIT_ARG_OWNER(uid, gid); NDINIT_ATRIGHTS(&nd, LOOKUP, at2cnpflags(flag, AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH | AT_EMPTY_PATH) | AUDITVNODE1, pathseg, path, @@ -4404,8 +4402,6 @@ int sys_getfhat(struct thread *td, struct getfhat_args *uap) { - if ((uap->flags & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH)) != 0) - return (EINVAL); return (kern_getfhat(td, uap->flags, uap->fd, uap->path, UIO_USERSPACE, uap->fhp, UIO_USERSPACE)); } @@ -4419,6 +4415,8 @@ kern_getfhat(struct thread *td, int flags, int fd, const char *path, struct vnode *vp; int error; + if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH)) != 0) + return (EINVAL); error = priv_check(td, PRIV_VFS_GETFH); if (error != 0) return (error);