From nobody Tue Feb 08 18:36:49 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 75B4619AA6AB; Tue, 8 Feb 2022 18:36:50 +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 4JtWv55Hk9z3qBG; Tue, 8 Feb 2022 18:36:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644345409; 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=qOETqJeIDGlZUkTUfvi8rNgHP3um7eqnJ6WRryrRYPs=; b=VA2iXREY6EOziIFmw+HZv7mOy/RNdZzlXVUEwuLbw0s/Oy3fLRG+YKRkvFqv1Xu9RIsevE UqzP2dUKYQa37ghkIbO1nkFa1nwMOft9qqnx/y8WPP17ixzEdimadjIoQ3pqxyEjYpTJiP uHnpN0cD9H+aAGVFXFoTRKx5lAEoJY0ayv/vffKFGIXYYBUvG1d6Nd5c7wIEjo+nQ28XVL Jixh5hX6dj4EYkpmcXT/nA7iRYHeF2XKwfZVVJzPC3CM+h1Ng7lf/db/vDVeFLVMv52nzu 2JCP1WvE1kJ7NbLR0ZZAesjQMlyWjLn3tmhprRtQcJ3AC4r5cWXEKfAEhpLw1w== 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 729151E646; Tue, 8 Feb 2022 18:36:49 +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 218Ian7m089109; Tue, 8 Feb 2022 18:36:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 218IanHd089108; Tue, 8 Feb 2022 18:36:49 GMT (envelope-from git) Date: Tue, 8 Feb 2022 18:36:49 GMT Message-Id: <202202081836.218IanHd089108@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: 300cfb96fc22 - main - file: Make fget*() and getvnode*() consistent about initializing *fpp 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: 300cfb96fc2253c3aff8d501d5599fcf811daa34 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644345409; 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=qOETqJeIDGlZUkTUfvi8rNgHP3um7eqnJ6WRryrRYPs=; b=AkAF3Kmr7KLgcPkZebBsPwMNHCbj4z3v9lbxzIWvA9FYfRv2hp+lY4BejlGBvrdF8tvPl9 iI33DXpnSQ0PSCkCJwDJrPDXDKHpb1cWYvX0gNyA93mabAaADFC5l1zra8ZoKTJTymK5yt O9id67gabe5EJsiqsoRgiOoMT2BtuhIIDHk+q0u/ueoziEztscdVDjiUqRjtXMEjMAXm05 jlgb9u+Uwd3w3zzpESdUfrF7UHwMMDhqBYkDKCIqnu67SpDUhiOMhDUz655Z77km8ajAu9 n0m9yEF5ovCiMDb7N/pL9UnvXHHzyjD5D9S/4TpfifvjPT5X91kV3dAEEp1NTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644345409; a=rsa-sha256; cv=none; b=ee7L3nLT7lgDzlY4KBeSSLUD8HO12nP5FNIqu5tz354L3wvDVZ+hMKuho8yZD80jDdRtkl jCQml7QZuwtjnKJsfUg9WGCRMiMe4Z7RE6Q2/0T5GxA83y4mqkmqaDxvfQOQDkbY4bfg9x xo9mRvtIE/r4T9zJ6aOCWpD9i5dDpOZGvK7Fa7r2ShjLIwZiyjxlJ6zcTsay7Ifxe4gSJ6 B1qeEpn+qWCczn4814EKH+kl5rfC4JJLY2MSA4CAuSqpKYOoCogTwpEd2uQIb+9aaQNjmz RrCrU/8FlJ3r+lT/YiwkaDs3eBsWU1/KUutu7qzVgSVKmlNPyGSpFDNnSvrA2w== 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=300cfb96fc2253c3aff8d501d5599fcf811daa34 commit 300cfb96fc2253c3aff8d501d5599fcf811daa34 Author: Mark Johnston AuthorDate: 2022-02-08 17:34:20 +0000 Commit: Mark Johnston CommitDate: 2022-02-08 17:40:41 +0000 file: Make fget*() and getvnode*() consistent about initializing *fpp Most fget*() functions initialize the output parameter to NULL. Make the externally visible interface behave consistently, and make fget_unlocked_seq() private to kern_descrip.c. This fixes at least one bug in a consumer, _filemon_wrapper_openat(), which assumes that getvnode() sets the output file pointer to NULL upon an error. Reported by: syzbot+01c0459408f896a5933a@syzkaller.appspotmail.com Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34190 --- sys/kern/kern_descrip.c | 12 ++++++++++-- sys/kern/vfs_syscalls.c | 2 ++ sys/sys/filedesc.h | 3 --- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index d5d22ecfc522..c4cf9abde664 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -115,6 +115,8 @@ static void fdgrowtable(struct filedesc *fdp, int nfd); static void fdgrowtable_exp(struct filedesc *fdp, int nfd); static void fdunused(struct filedesc *fdp, int fd); static void fdused(struct filedesc *fdp, int fd); +static int fget_unlocked_seq(struct filedesc *fdp, int fd, + cap_rights_t *needrightsp, struct file **fpp, seqc_t *seqp); static int getmaxfd(struct thread *td); static u_long *filecaps_copy_prep(const struct filecaps *src); static void filecaps_copy_finish(const struct filecaps *src, @@ -2843,6 +2845,7 @@ fget_cap_locked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, FILEDESC_LOCK_ASSERT(fdp); + *fpp = NULL; fde = fdeget_locked(fdp, fd); if (fde == NULL) { error = EBADF; @@ -3014,7 +3017,7 @@ fgetvp_lookup_smr(int fd, struct nameidata *ndp, struct vnode **vpp, bool *fsear } #endif -int +static int fget_unlocked_seq(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp, seqc_t *seqp) { @@ -3112,8 +3115,10 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, #endif fdt = fdp->fd_files; - if (__predict_false((u_int)fd >= fdt->fdt_nfiles)) + if (__predict_false((u_int)fd >= fdt->fdt_nfiles)) { + *fpp = NULL; return (EBADF); + } #ifdef CAPABILITIES seq = seqc_read_notmodify(fd_seqc(fdt, fd)); fde = &fdt->fdt_ofiles[fd]; @@ -3148,6 +3153,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, out_fdrop: fdrop(fp, curthread); out_fallback: + *fpp = NULL; return (fget_unlocked_seq(fdp, fd, needrightsp, fpp, NULL)); } @@ -3173,6 +3179,7 @@ fget_only_user(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, MPASS(FILEDESC_IS_ONLY_USER(fdp)); + *fpp = NULL; if (__predict_false(fd >= fdp->fd_nfiles)) return (EBADF); @@ -3198,6 +3205,7 @@ fget_only_user(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, MPASS(FILEDESC_IS_ONLY_USER(fdp)); + *fpp = NULL; if (__predict_false(fd >= fdp->fd_nfiles)) return (EBADF); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 3e0b96051465..5549cae570f8 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -4336,6 +4336,7 @@ getvnode_path(struct thread *td, int fd, cap_rights_t *rightsp, */ if (__predict_false(fp->f_vnode == NULL || fp->f_ops == &badfileops)) { fdrop(fp, td); + *fpp = NULL; return (EINVAL); } @@ -4363,6 +4364,7 @@ getvnode(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp) */ if (__predict_false((*fpp)->f_ops == &path_fileops)) { fdrop(*fpp, td); + *fpp = NULL; error = EBADF; } diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 6f0e74e70d3b..f003c0ff3c4b 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -269,10 +269,7 @@ int fget_cap_locked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp, struct filecaps *havecapsp); int fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, struct file **fpp, struct filecaps *havecapsp); - /* Return a referenced file from an unlocked descriptor. */ -int fget_unlocked_seq(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, - struct file **fpp, seqc_t *seqp); int fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp); /* Return a file pointer without a ref. FILEDESC_IS_ONLY_USER must be true. */