ufs: Prevent mkdir from choking on deleted directories.

Fix some missing uvm_vnp_setsize in screw cases while here.
This commit is contained in:
riastradh 2020-09-05 02:47:48 +00:00
parent 44afc3b3f9
commit 4b73975959
5 changed files with 27 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vnops.c,v 1.333 2020/05/16 18:31:53 christos Exp $ */
/* $NetBSD: lfs_vnops.c,v 1.334 2020/09/05 02:47:48 riastradh Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -125,7 +125,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.333 2020/05/16 18:31:53 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.334 2020/09/05 02:47:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -991,6 +991,13 @@ lfs_mkdir(void *v)
*ap->a_vpp = NULL;
goto out;
}
if (VTOI(*ap->a_vpp)->i_size == 0) {
/* directory has been rmdir'd */
vput(*ap->a_vpp);
*ap->a_vpp = NULL;
error = ENOENT;
goto out;
}
tvp = *ap->a_vpp;
MARK_VNODE(tvp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ulfs_lookup.c,v 1.44 2020/05/16 18:31:53 christos Exp $ */
/* $NetBSD: ulfs_lookup.c,v 1.45 2020/09/05 02:47:48 riastradh Exp $ */
/* from NetBSD: ufs_lookup.c,v 1.135 2015/07/11 11:04:48 mlelstv */
/*
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.44 2020/05/16 18:31:53 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.45 2020/09/05 02:47:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_lfs.h"
@ -522,6 +522,7 @@ found:
results->ulr_offset + LFS_DIRSIZ(fs, ep);
DIP_ASSIGN(dp, size, dp->i_size);
dp->i_state |= IN_CHANGE | IN_UPDATE;
uvm_vnp_setsize(vdp, dp->i_size);
}
brelse(bp, 0);
@ -846,6 +847,7 @@ ulfs_direnter(struct vnode *dvp, const struct ulfs_lookup_results *ulr,
dp->i_size = ulr->ulr_offset + ulr->ulr_count;
DIP_ASSIGN(dp, size, dp->i_size);
dp->i_state |= IN_CHANGE | IN_UPDATE;
uvm_vnp_setsize(dvp, dp->i_size);
}
/*
* Get the block containing the space for the new directory entry.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_lookup.c,v 1.153 2020/05/16 18:31:54 christos Exp $ */
/* $NetBSD: ufs_lookup.c,v 1.154 2020/09/05 02:47:48 riastradh Exp $ */
/*
* Copyright (c) 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.153 2020/05/16 18:31:54 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.154 2020/09/05 02:47:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_ffs.h"
@ -667,6 +667,7 @@ found:
dp->i_size = newisize;
DIP_ASSIGN(dp, size, dp->i_size);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
uvm_vnp_setsize(vdp, dp->i_size);
UFS_WAPBL_UPDATE(vdp, NULL, NULL, UPDATE_DIROP);
}
brelse(bp, 0);
@ -956,6 +957,7 @@ ufs_dircompact(struct vnode *dvp, const struct ufs_lookup_results *ulr,
dp->i_size = ulr->ulr_offset + ulr->ulr_count;
DIP_ASSIGN(dp, size, dp->i_size);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
uvm_vnp_setsize(dvp, dp->i_size);
UFS_WAPBL_UPDATE(dvp, NULL, NULL, UPDATE_DIROP);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_vnops.c,v 1.256 2020/08/20 20:28:13 christos Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.257 2020/09/05 02:47:48 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.256 2020/08/20 20:28:13 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.257 2020/09/05 02:47:48 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -1253,6 +1253,13 @@ ufs_mkdir(void *v)
*ap->a_vpp = NULL;
goto out;
}
if (VTOI(*ap->a_vpp)->i_size == 0) {
/* directory has been rmdir'd */
vput(*ap->a_vpp);
*ap->a_vpp = NULL;
error = ENOENT;
goto out;
}
error = UFS_WAPBL_BEGIN(ap->a_dvp->v_mount);
if (error) {
vput(*ap->a_vpp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_renamerace.c,v 1.38 2020/09/05 02:47:03 riastradh Exp $ */
/* $NetBSD: t_renamerace.c,v 1.39 2020/09/05 02:47:49 riastradh Exp $ */
/*
* Modified for rump and atf from a program supplied
@ -248,8 +248,6 @@ renamerace_cycle(const atf_tc_t *tc, const char *mp)
atf_tc_skip("directories not supported by file system");
if (FSTYPE_RUMPFS(tc))
atf_tc_skip("rename not supported by file system");
if (FSTYPE_P2K_FFS(tc))
atf_tc_expect_fail("assertion \"vp->v_size == ip->i_size\" failed");
if (FSTYPE_PUFFS(tc))
atf_tc_expect_fail("assertion \"dfd\" failed");
if (FSTYPE_NFS(tc))