Skip to content

Commit

Permalink
Merge branch 'freebsd/11-stable/master' into hardened/11-stable/master
Browse files Browse the repository at this point in the history
* freebsd/11-stable/master:
  MFC r340257
  MFC r340898: Ensure that knotes do not get registered when KQ_CLOSING is set.
  MFC r340897: Lock the knlist before releasing the in-flux state in knote_fork().
  MFC r340899: Plug some kernel memory disclosures via kevent(2).
  MFC r340856: Ensure that directory entry padding bytes are zeroed.
  • Loading branch information
opntr-auto committed Nov 27, 2018
2 parents ba099c7 + 755e888 commit abef56f
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 50 deletions.
6 changes: 4 additions & 2 deletions sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ sfs_readdir_common(uint64_t parent_id, uint64_t id, struct vop_readdir_args *ap,
entry.d_fileno = id;
entry.d_type = DT_DIR;
entry.d_name[0] = '.';
entry.d_name[1] = '\0';
entry.d_namlen = 1;
entry.d_reclen = sizeof(entry);
dirent_terminate(&entry);
error = vfs_read_dirent(ap, &entry, uio->uio_offset);
if (error != 0)
return (SET_ERROR(error));
Expand All @@ -277,9 +277,9 @@ sfs_readdir_common(uint64_t parent_id, uint64_t id, struct vop_readdir_args *ap,
entry.d_type = DT_DIR;
entry.d_name[0] = '.';
entry.d_name[1] = '.';
entry.d_name[2] = '\0';
entry.d_namlen = 2;
entry.d_reclen = sizeof(entry);
dirent_terminate(&entry);
error = vfs_read_dirent(ap, &entry, uio->uio_offset);
if (error != 0)
return (SET_ERROR(error));
Expand Down Expand Up @@ -694,6 +694,7 @@ zfsctl_root_readdir(ap)
strcpy(entry.d_name, node->snapdir->sn_name);
entry.d_namlen = strlen(entry.d_name);
entry.d_reclen = sizeof(entry);
dirent_terminate(&entry);
error = vfs_read_dirent(ap, &entry, uio->uio_offset);
if (error != 0) {
if (error == ENAMETOOLONG)
Expand Down Expand Up @@ -1097,6 +1098,7 @@ zfsctl_snapdir_readdir(ap)
strcpy(entry.d_name, snapname);
entry.d_namlen = strlen(entry.d_name);
entry.d_reclen = sizeof(entry);
dirent_terminate(&entry);
error = vfs_read_dirent(ap, &entry, uio->uio_offset);
if (error != 0) {
if (error == ENAMETOOLONG)
Expand Down
1 change: 1 addition & 0 deletions sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,7 @@ zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp, int *ncookies, u_lon
odp->d_namlen = strlen(zap.za_name);
(void) strlcpy(odp->d_name, zap.za_name, odp->d_namlen + 1);
odp->d_type = type;
dirent_terminate(odp);
odp = (dirent64_t *)((intptr_t)odp + reclen);
}
outcount += reclen;
Expand Down
5 changes: 2 additions & 3 deletions sys/fs/autofs/autofs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/condvar.h>
#include <sys/dirent.h>
Expand All @@ -44,7 +45,6 @@ __FBSDID("$FreeBSD$");
#include <sys/namei.h>
#include <sys/signalvar.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/taskqueue.h>
#include <sys/tree.h>
#include <sys/vnode.h>
Expand Down Expand Up @@ -361,7 +361,6 @@ autofs_readdir_one(struct uio *uio, const char *name, int fileno,
padded_namlen = roundup2(namlen + 1, __alignof(struct dirent));
KASSERT(padded_namlen <= MAXNAMLEN, ("%zd > MAXNAMLEN", padded_namlen));
reclen = offsetof(struct dirent, d_name) + padded_namlen;

if (reclenp != NULL)
*reclenp = reclen;

Expand All @@ -376,7 +375,7 @@ autofs_readdir_one(struct uio *uio, const char *name, int fileno,
dirent.d_type = DT_DIR;
dirent.d_namlen = namlen;
memcpy(dirent.d_name, name, namlen);
memset(dirent.d_name + namlen, 0, padded_namlen - namlen);
dirent_terminate(&dirent);
error = uiomove(&dirent, reclen, uio);

return (error);
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/cd9660/cd9660_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ iso_uiodir(idp,dp,off)
{
int error;

dp->d_name[dp->d_namlen] = 0;
dp->d_reclen = GENERIC_DIRSIZ(dp);
dirent_terminate(dp);

if (idp->uio->uio_resid < dp->d_reclen) {
idp->eofflag = 0;
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/devfs/devfs_devs.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ devfs_newdirent(char *name, int namelen)
de->de_dirent->d_namlen = namelen;
de->de_dirent->d_reclen = GENERIC_DIRSIZ(&d);
bcopy(name, de->de_dirent->d_name, namelen);
de->de_dirent->d_name[namelen] = '\0';
dirent_terminate(de->de_dirent);
vfs_timestamp(&de->de_ctime);
de->de_mtime = de->de_atime = de->de_ctime;
de->de_links = 1;
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/ext2fs/ext2_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ext2_readdir(struct vop_readdir_args *ap)
dstdp.d_fileno = dp->e2d_ino;
dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
bcopy(dp->e2d_name, dstdp.d_name, dstdp.d_namlen);
dstdp.d_name[dstdp.d_namlen] = '\0';
dirent_terminate(&dstdp);
if (dstdp.d_reclen > uio->uio_resid) {
if (uio->uio_resid == startresid)
error = EINVAL;
Expand Down
3 changes: 2 additions & 1 deletion sys/fs/fdescfs/fdesc_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ fdesc_readdir(struct vop_readdir_args *ap)
dp->d_namlen = i + 1;
dp->d_reclen = UIO_MX;
bcopy("..", dp->d_name, dp->d_namlen);
dp->d_name[i + 1] = '\0';
dp->d_type = DT_DIR;
dirent_terminate(dp);
break;
default:
if (fdp->fd_ofiles[fcnt].fde_file == NULL)
Expand All @@ -571,6 +571,7 @@ fdesc_readdir(struct vop_readdir_args *ap)
dp->d_type = (fmp->flags & FMNT_LINRDLNKF) == 0 ?
DT_CHR : DT_LNK;
dp->d_fileno = i + FD_DESC;
dirent_terminate(dp);
break;
}
if (dp->d_namlen != 0) {
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/fuse/fuse_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fuse_internal_readdir_processdata(struct uio *uio,
memcpy((char *)cookediov->base + sizeof(struct dirent) -
MAXNAMLEN - 1,
(char *)buf + FUSE_NAME_OFFSET, fudge->namelen);
((char *)cookediov->base)[bytesavail - 1] = '\0';
dirent_terminate(de);

err = uiomove(cookediov->base, cookediov->len, uio);
if (err) {
Expand Down
6 changes: 4 additions & 2 deletions sys/fs/msdosfs/msdosfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1561,14 +1561,16 @@ msdosfs_readdir(struct vop_readdir_args *ap)
switch (n) {
case 0:
dirbuf.d_namlen = 1;
strcpy(dirbuf.d_name, ".");
dirbuf.d_name[0] = '.';
break;
case 1:
dirbuf.d_namlen = 2;
strcpy(dirbuf.d_name, "..");
dirbuf.d_name[0] = '.';
dirbuf.d_name[1] = '.';
break;
}
dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
dirent_terminate(&dirbuf);
if (uio->uio_resid < dirbuf.d_reclen)
goto out;
error = uiomove(&dirbuf, dirbuf.d_reclen, uio);
Expand Down
5 changes: 3 additions & 2 deletions sys/fs/nandfs/nandfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,13 +1225,14 @@ nandfs_readdir(struct vop_readdir_args *ap)
ndirent = (struct nandfs_dir_entry *)pos;

name_len = ndirent->name_len;
memset(&dirent, 0, sizeof(struct dirent));
memset(&dirent, 0, sizeof(dirent));
dirent.d_fileno = ndirent->inode;
if (dirent.d_fileno) {
dirent.d_type = ndirent->file_type;
dirent.d_namlen = name_len;
strncpy(dirent.d_name, ndirent->name, name_len);
dirent.d_reclen = GENERIC_DIRSIZ(&dirent);
dirent_terminate(&dirent);
DPRINTF(READDIR, ("copying `%*.*s`\n", name_len,
name_len, dirent.d_name));
}
Expand All @@ -1245,7 +1246,7 @@ nandfs_readdir(struct vop_readdir_args *ap)

/* Transfer */
if (dirent.d_fileno)
uiomove(&dirent, GENERIC_DIRSIZ(&dirent), uio);
uiomove(&dirent, dirent.d_reclen, uio);

/* Advance */
diroffset += ndirent->rec_len;
Expand Down
16 changes: 8 additions & 8 deletions sys/fs/nfsclient/nfs_clrpcops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,7 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
tlen += 4; /* To ensure null termination */
left = DIRBLKSIZ - blksiz;
if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > left) {
NFSBZERO(uio_iov_base(uiop), left);
dp->d_reclen += left;
uio_iov_base_add(uiop, left);
uio_iov_len_add(uiop, -(left));
Expand All @@ -3062,7 +3063,7 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
goto nfsmout;
cp = CAST_DOWN(caddr_t, uio_iov_base(uiop));
tlen -= len;
*cp = '\0'; /* null terminate */
NFSBZERO(cp, tlen);
cp += tlen; /* points to cookie storage */
tl2 = (u_int32_t *)cp;
uio_iov_base_add(uiop, (tlen + NFSX_HYPER));
Expand Down Expand Up @@ -3150,6 +3151,7 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
*/
if (blksiz > 0) {
left = DIRBLKSIZ - blksiz;
NFSBZERO(uio_iov_base(uiop), left);
dp->d_reclen += left;
uio_iov_base_add(uiop, left);
uio_iov_len_add(uiop, -(left));
Expand Down Expand Up @@ -3177,10 +3179,8 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
*/
while (uio_uio_resid(uiop) > 0 && ((size_t)(uio_uio_resid(uiop))) != tresid) {
dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
NFSBZERO(dp, DIRBLKSIZ);
dp->d_type = DT_UNKNOWN;
dp->d_fileno = 0;
dp->d_namlen = 0;
dp->d_name[0] = '\0';
tl = (u_int32_t *)&dp->d_name[4];
*tl++ = cookie.lval[0];
*tl = cookie.lval[1];
Expand Down Expand Up @@ -3444,6 +3444,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
tlen += 4; /* To ensure null termination */
left = DIRBLKSIZ - blksiz;
if ((tlen + DIRHDSIZ + NFSX_HYPER) > left) {
NFSBZERO(uio_iov_base(uiop), left);
dp->d_reclen += left;
uio_iov_base_add(uiop, left);
uio_iov_len_add(uiop, -(left));
Expand Down Expand Up @@ -3473,7 +3474,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
goto nfsmout;
cp = uio_iov_base(uiop);
tlen -= len;
*cp = '\0';
NFSBZERO(cp, tlen);
cp += tlen; /* points to cookie storage */
tl2 = (u_int32_t *)cp;
if (len == 2 && cnp->cn_nameptr[0] == '.' &&
Expand Down Expand Up @@ -3643,6 +3644,7 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
*/
if (blksiz > 0) {
left = DIRBLKSIZ - blksiz;
NFSBZERO(uio_iov_base(uiop), left);
dp->d_reclen += left;
uio_iov_base_add(uiop, left);
uio_iov_len_add(uiop, -(left));
Expand Down Expand Up @@ -3670,10 +3672,8 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
*/
while (uio_uio_resid(uiop) > 0 && uio_uio_resid(uiop) != tresid) {
dp = (struct dirent *)uio_iov_base(uiop);
NFSBZERO(dp, DIRBLKSIZ);
dp->d_type = DT_UNKNOWN;
dp->d_fileno = 0;
dp->d_namlen = 0;
dp->d_name[0] = '\0';
tl = (u_int32_t *)&dp->d_name[4];
*tl++ = cookie.lval[0];
*tl = cookie.lval[1];
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/pseudofs/pseudofs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ pfs_readdir(struct vop_readdir_args *va)
/* PFS_DELEN was picked to fit PFS_NAMLEN */
for (i = 0; i < PFS_NAMELEN - 1 && pn->pn_name[i] != '\0'; ++i)
pfsent->entry.d_name[i] = pn->pn_name[i];
pfsent->entry.d_name[i] = 0;
pfsent->entry.d_namlen = i;
switch (pn->pn_type) {
case pfstype_procdir:
Expand All @@ -851,6 +850,7 @@ pfs_readdir(struct vop_readdir_args *va)
panic("%s has unexpected node type: %d", pn->pn_name, pn->pn_type);
}
PFS_TRACE(("%s", pfsent->entry.d_name));
dirent_terminate(&pfsent->entry);
STAILQ_INSERT_TAIL(&lst, pfsent, link);
offset += PFS_DELEN;
resid -= PFS_DELEN;
Expand Down
4 changes: 2 additions & 2 deletions sys/fs/smbfs/smbfs_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred)
de.d_namlen = offset + 1;
de.d_name[0] = '.';
de.d_name[1] = '.';
de.d_name[offset + 1] = '\0';
de.d_type = DT_DIR;
dirent_terminate(&de);
error = uiomove(&de, DE_SIZE, uio);
if (error)
goto out;
Expand Down Expand Up @@ -154,7 +154,7 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred)
de.d_type = (ctx->f_attr.fa_attr & SMB_FA_DIR) ? DT_DIR : DT_REG;
de.d_namlen = ctx->f_nmlen;
bcopy(ctx->f_name, de.d_name, de.d_namlen);
de.d_name[de.d_namlen] = '\0';
dirent_terminate(&de);
if (smbfs_fastlookup) {
error = smbfs_nget(vp->v_mount, vp, ctx->f_name,
ctx->f_nmlen, &ctx->f_attr, &newvp);
Expand Down
9 changes: 5 additions & 4 deletions sys/fs/tmpfs/tmpfs_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/dirent.h>
#include <sys/fnv_hash.h>
#include <sys/lock.h>
#include <sys/namei.h>
Expand All @@ -45,7 +47,6 @@ __FBSDID("$FreeBSD$");
#include <sys/random.h>
#include <sys/rwlock.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
#include <sys/vmmeter.h>
Expand Down Expand Up @@ -1115,8 +1116,8 @@ tmpfs_dir_getdotdent(struct tmpfs_node *node, struct uio *uio)
dent.d_type = DT_DIR;
dent.d_namlen = 1;
dent.d_name[0] = '.';
dent.d_name[1] = '\0';
dent.d_reclen = GENERIC_DIRSIZ(&dent);
dirent_terminate(&dent);

if (dent.d_reclen > uio->uio_resid)
error = EJUSTRETURN;
Expand Down Expand Up @@ -1159,8 +1160,8 @@ tmpfs_dir_getdotdotdent(struct tmpfs_node *node, struct uio *uio)
dent.d_namlen = 2;
dent.d_name[0] = '.';
dent.d_name[1] = '.';
dent.d_name[2] = '\0';
dent.d_reclen = GENERIC_DIRSIZ(&dent);
dirent_terminate(&dent);

if (dent.d_reclen > uio->uio_resid)
error = EJUSTRETURN;
Expand Down Expand Up @@ -1280,8 +1281,8 @@ tmpfs_dir_getdents(struct tmpfs_node *node, struct uio *uio, int maxcookies,
d.d_namlen = de->td_namelen;
MPASS(de->td_namelen < sizeof(d.d_name));
(void)memcpy(d.d_name, de->ud.td_name, de->td_namelen);
d.d_name[de->td_namelen] = '\0';
d.d_reclen = GENERIC_DIRSIZ(&d);
dirent_terminate(&d);

/* Stop reading if the directory entry we are treating is
* bigger than the amount of data that can be returned. */
Expand Down
1 change: 0 additions & 1 deletion sys/fs/tmpfs/tmpfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h>
#include <sys/rwlock.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/sysctl.h>

#include <vm/vm.h>
Expand Down
1 change: 0 additions & 1 deletion sys/fs/tmpfs/tmpfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$");
#include <sys/rwlock.h>
#include <sys/sched.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/sysctl.h>
#include <sys/unistd.h>
#include <sys/vnode.h>
Expand Down
5 changes: 3 additions & 2 deletions sys/fs/udf/udf_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ udf_readdir(struct vop_readdir_args *a)
dir.d_fileno = node->hash_id;
dir.d_type = DT_DIR;
dir.d_name[0] = '.';
dir.d_name[1] = '\0';
dir.d_namlen = 1;
dir.d_reclen = GENERIC_DIRSIZ(&dir);
dirent_terminate(&dir);
uiodir.dirent = &dir;
error = udf_uiodir(&uiodir, dir.d_reclen, uio, 1);
if (error)
Expand All @@ -853,9 +853,9 @@ udf_readdir(struct vop_readdir_args *a)
dir.d_type = DT_DIR;
dir.d_name[0] = '.';
dir.d_name[1] = '.';
dir.d_name[2] = '\0';
dir.d_namlen = 2;
dir.d_reclen = GENERIC_DIRSIZ(&dir);
dirent_terminate(&dir);
uiodir.dirent = &dir;
error = udf_uiodir(&uiodir, dir.d_reclen, uio, 2);
} else {
Expand All @@ -865,6 +865,7 @@ udf_readdir(struct vop_readdir_args *a)
dir.d_type = (fid->file_char & UDF_FILE_CHAR_DIR) ?
DT_DIR : DT_UNKNOWN;
dir.d_reclen = GENERIC_DIRSIZ(&dir);
dirent_terminate(&dir);
uiodir.dirent = &dir;
error = udf_uiodir(&uiodir, dir.d_reclen, uio,
ds->this_off);
Expand Down
Loading

0 comments on commit abef56f

Please sign in to comment.