From owner-svn-src-head@freebsd.org Wed Feb 5 00:20:27 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1E22F239BC6; Wed, 5 Feb 2020 00:20:27 +0000 (UTC) (envelope-from mjg@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48C2Jp73vPz3KCJ; Wed, 5 Feb 2020 00:20:26 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EDBEC2219B; Wed, 5 Feb 2020 00:20:26 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0150KQTb028311; Wed, 5 Feb 2020 00:20:26 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0150KQJV028310; Wed, 5 Feb 2020 00:20:26 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202002050020.0150KQJV028310@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 5 Feb 2020 00:20:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357554 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 357554 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Feb 2020 00:20:27 -0000 Author: mjg Date: Wed Feb 5 00:20:26 2020 New Revision: 357554 URL: https://svnweb.freebsd.org/changeset/base/357554 Log: fd: always nullify *fdp in fget* routines Some consumers depend on the pointer being NULL if an error is returned. The guarantee got broken in r357469. Reported by: https://syzkaller.appspot.com/bug?extid=0c9b05e2b727aae21eef Noted by: markj Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Wed Feb 5 00:13:15 2020 (r357553) +++ head/sys/kern/kern_descrip.c Wed Feb 5 00:20:26 2020 (r357554) @@ -2651,6 +2651,7 @@ fget_cap(struct thread *td, int fd, cap_rights_t *need struct file *fp; seqc_t seq; + *fpp = NULL; for (;;) { error = fget_unlocked_seq(fdp, fd, needrightsp, &fp, &seq); if (error != 0) @@ -2905,26 +2906,29 @@ fget_mmap(struct thread *td, int fd, cap_rights_t *rig error = _fget(td, fd, fpp, 0, rightsp); if (maxprotp != NULL) *maxprotp = VM_PROT_ALL; + return (error); #else cap_rights_t fdrights; struct filedesc *fdp; + struct file *fp; seqc_t seq; + *fpp = NULL; fdp = td->td_proc->p_fd; MPASS(cap_rights_is_set(rightsp, CAP_MMAP)); for (;;) { - error = fget_unlocked_seq(fdp, fd, rightsp, fpp, &seq); + error = fget_unlocked_seq(fdp, fd, rightsp, &fp, &seq); if (__predict_false(error != 0)) return (error); - if (__predict_false((*fpp)->f_ops == &badfileops)) { - fdrop(*fpp, td); + if (__predict_false(fp->f_ops == &badfileops)) { + fdrop(fp, td); return (EBADF); } if (maxprotp != NULL) fdrights = *cap_rights(fdp, fd); if (!fd_modified(fdp, fd, seq)) break; - fdrop(*fpp, td); + fdrop(fp, td); } /* @@ -2932,8 +2936,9 @@ fget_mmap(struct thread *td, int fd, cap_rights_t *rig */ if (maxprotp != NULL) *maxprotp = cap_rights_to_vmprot(&fdrights); + *fpp = fp; + return (0); #endif - return (error); } int @@ -2958,24 +2963,27 @@ fget_fcntl(struct thread *td, int fd, cap_rights_t *ri #ifndef CAPABILITIES return (fget_unlocked(fdp, fd, rightsp, fpp)); #else + struct file *fp; int error; seqc_t seq; + *fpp = NULL; MPASS(cap_rights_is_set(rightsp, CAP_FCNTL)); for (;;) { - error = fget_unlocked_seq(fdp, fd, rightsp, fpp, &seq); + error = fget_unlocked_seq(fdp, fd, rightsp, &fp, &seq); if (error != 0) return (error); error = cap_fcntl_check(fdp, fd, needfcntl); if (!fd_modified(fdp, fd, seq)) break; - fdrop(*fpp, td); + fdrop(fp, td); } if (error != 0) { - fdrop(*fpp, td); - *fpp = NULL; + fdrop(fp, td); + return (error); } - return (error); + *fpp = fp; + return (0); #endif }