Commit Graph

799 Commits

Author SHA1 Message Date
maxv
795334fc6b ffs_superblock_validate(): ensure fs_ncg!=0 and fs_maxbpg!=0 to prevent
several divisions by zero.
2015-04-04 06:00:12 +00:00
maxv
6e39240181 Remove the 'cred' argument from bread(). Remove a now unused var in
ffs_snapshot.c. Update the man page accordingly.

ok hannken@
2015-03-28 19:24:04 +00:00
maxv
bb338d5f26 Remove the 'cred' argument from breadn(), and update the man page
accordingly.

ok hannken@
2015-03-28 17:23:42 +00:00
riastradh
5a2d83e099 Disentangle buffer-cached I/O from page-cached I/O in UFS.
Page-cached I/O is used for regular files, and is initiated by VFS
users such as userland and NFS.

Buffer-cached I/O is used for directories and symlinks, and is issued
only internally by UFS.

New UFS routine ufs_bufio replaces vn_rdwr for internal use.
ufs_bufio is implemented by new UFS operations uo_bufrd/uo_bufwr,
which sit in ufs_readwrite.c alongside the VOP_READ/VOP_WRITE
implementations.

I preserved the code as much as possible and will leave further
simplification for future commits.  I kept the ulfs_readwrite.c
copypasta close to ufs_readwrite.c in case we ever want to merge them
back; likewise ext2fs_readwrite.c.

No externally visible semantic change.  All atf fs tests still pass.
2015-03-27 17:27:55 +00:00
hannken
54fa474e3e Change ffs to use vcache_new:
- Change ffs_valloc to return an inode number.
- Remove now obsolete UFS operations UFS_VALLOC and UFS_VFREE.
- Make ufs_makeinode private to ufs_vnops.c and pass vattr instead of mode.
2015-03-17 09:39:29 +00:00
maxv
9eec611462 ffs_reload(): fix a bug that prevents Big Endian FSes from being reloaded.
'newfs' should be tagged as FS_SWAPPED, not 'fs'.

Was here before my changes.

While here, also KNF a bit.
2015-03-15 09:21:01 +00:00
maxv
a578b5382f ffs_superblock_validate(): ensure fs_ipg and fs_fpg are != 0. Otherwise
division by zero in several places.
2015-03-14 19:52:54 +00:00
maxv
18abcb4757 ffs_superblock_validate(): check the number of inodes per block. Otherwise
a malformed value could panic the system.
2015-03-10 12:59:32 +00:00
maxv
c84267386a ffs_reload(): release 'bp' earlier 2015-03-03 17:56:51 +00:00
maxv
e6e56ce208 ffs_reload(): the current implementation blindly guesses critical fields
of the superblock didn't change. Add checks to ensure they didn't change
for real. This prevents several memory corruptions.
2015-03-03 17:46:39 +00:00
maxv
5f9c472c31 Small changes:
- instead of always calling DPRINTF with __func__, put __func__ directly
   in the macro
 - ffs_mountfs(): rename fsblockloc -> fs_sblockloc, initialize fs_sbsize
   to zero
No real functional change
2015-02-23 13:38:54 +00:00
maxv
81c691b934 ffs_superblock_validate(): sanitize fs_fragshift, fs_bmask and fs_fmask. 2015-02-22 14:22:34 +00:00
maxv
8cadf998b5 KNF, and simplify a bit.
No functional change
2015-02-22 14:12:48 +00:00
maxv
afc7ff8c74 Style, and fix a DPRINTF
No functional change
2015-02-20 17:10:17 +00:00
maxv
12c9fae830 Revert a change in my previous commit that broke the checksum calculation.
Noted by dholland@
2015-02-15 11:04:43 +00:00
maxv
f2f615bb86 ffs_superblock_validate(): when checking the number of frag blocks, also
make sure it matches fs->fs_frag. This also prevents an infinite loop if
fs->fs_frag=0.
2015-02-14 13:43:28 +00:00
maxv
cba38714c3 ffs_superblock_validate(): compute fs_bshift and fs_fshift, and ensure
they are consistent with what is indicated in the superblock. This allows
us to safely use some ffs_ macros.
2015-02-14 10:21:29 +00:00
maxv
7fcc4ddf11 In fact, we need to sanitize the superblock *after* swapping it. Therefore,
move the swap code inside the loop.

'fs->fs_sbsize' is swapped twice: the first time in order to get the
correct superblock size, and later when swapping the whole superblock
structure. As a result, we need to check 'fs->fs_sbsize' twice.

This:
 - fixes my previous changes for swapped FSes
 - allows the kernel to look for other superblock locations if the
   current superblock is not validated

And now:
 - ffs_superblock_validate() takes only one argument: the fs structure
 - 'fs_bsize' is unused, so delete it

Add some comments to explain a bit what we are doing.
2015-02-14 09:55:53 +00:00
maxv
a42dfe11dc Two typos:
- "preferrably" -> "preferably"
 - "overriden" -> "overridden"
No functional change.
2015-02-14 09:06:11 +00:00
maxv
dd5da7d8bc ffs_superblock_validate(): sanitize the number of frag blocks. 2015-02-14 09:00:12 +00:00
maxv
4d2092869c ffs_appleufs_validate():
- remove superfluous printfs
 - ensure ul_namelen!=0, otherwise the kernel accesses ul_name[-1] and
   overwrites the previous field in the structure.
2015-02-14 08:07:39 +00:00
maxv
55a23d9c1d KNF. No functional change. 2015-02-14 07:56:31 +00:00
maxv
e54cf2b426 Currently, in ffs_reload(), we don't handle the possibility that the
superblock location may have changed. But that implies that we don't
handle the possibility that its size may have changed either.

Therefore: add a check to ensure the size hasn't changed. Otherwise the
mismatch leads to a memory corruption with kmem.
2015-02-14 07:41:40 +00:00
maxv
8f21e79caf Style. No functional change. 2015-02-14 07:20:11 +00:00
maxv
dc85b9beea ffs_reload(): call ffs_superblock_validate() with the new superblock. 2015-02-14 07:11:34 +00:00
maxv
e700b847ac ffs_superblock_validate(): ensure fs->fs_cssize!=0, otherwise the kernel
panics with kmem_alloc(0).
2015-02-13 17:13:20 +00:00
maxv
9f7cd5d78c Add some checks in ffs_superblock_validate():
- fs_bsize < MINBSIZE
 - !powerof2(fs_bsize)
 - !powerof2(fs->fs_fsize)
 - fs_bsize < fs->fs_fsize

Based on makefs/ffs.
2015-02-13 16:59:52 +00:00
maxv
08df7d11c2 Add a new function: ffs_superblock_validate(). And add a new check to
ensure fs_size!=0; otherwise the kernel panics with a division by zero.
2015-02-13 15:52:29 +00:00
maxv
17e3fa0477 Make this a bit more readable. No functional change. 2015-02-13 15:28:56 +00:00
christos
bb54e0e08c PR/39371: Tobias Nygren: Don't fail mounting root if WAPBL log is corrupt.
Patch from Sergio L. Pascual.
XXX: pullup-7
2015-01-16 03:57:52 +00:00
christos
853279d741 Restore apple ufs error handling. 2014-12-14 01:13:57 +00:00
christos
4ddba2941f - Add debugging for mount...
- Merge some error returns
- Check more errors
2014-12-14 00:36:07 +00:00
manu
7ac57848aa Fix use-after-free on failed unmount with extended attribute enabled
When unmount failed, for instance because the mount is still busy,
UFS1 extended attributes structures were left freed while the kernel
assumes extended attributes were still enabled. This led to using
UFS1 extended attributes structures after free. With LOCKDEBUG, with
quickly triggers a panic.

The problem is fixed by:
1) clear MNT_EXTATTR flag after extended attributes structures are freed
2) attempt to restart extended attributes after failed unmount
2) set MNT_EXTATTR correctly after extended attributes restart

As a side effect, extended attribute structures are now only initialized
when extended attributes are started for the filesystem.
2014-11-14 10:09:50 +00:00
maxv
86c13aa357 Limit the superblock size to SBLOCKSIZE, not MAXBSIZE. Otherwise memcpy
will read beyond the allocated buffer.

Discussed a bit on tech-kern@.
2014-10-30 17:13:41 +00:00
njoly
3ab1cc3d9a One semicolon is enough. 2014-10-24 13:18:51 +00:00
joerg
42af341101 Prefer cprng_fast32 over random. A good distribution even in the lower
bits beat any minor performance advantage randomo(9) might have,
especially given the disk IO involved.
2014-09-08 20:52:37 +00:00
matt
9d33f033c0 Don't nest structure definitions. 2014-09-05 06:10:07 +00:00
dholland
5366fdc4a7 Switch the FFS code for discarding free blocks to use VOP_FDISCARD. 2014-07-25 08:24:31 +00:00
dholland
05d075b3ae Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.
2014-07-25 08:20:51 +00:00
christos
cb7ffd4c7b move the flag setting higher to avoid KASSERT (dholland) 2014-07-11 16:17:29 +00:00
christos
0a57ec5aa3 CID 975226: hande error from UFS_WAPBL_BEGIN 2014-07-10 15:15:54 +00:00
dholland
42bd51ac43 Fix unchecked UFS_WAPBL_BEGIN. Coverity 975226.
Unfortunately it looks like all we can do on error here is printf.
2014-07-10 06:27:15 +00:00
dholland
e1f8b7119c Use an explicit compare to 0 for an immediate error result, not !.
Using ! is perfectly clear on variables like "error" or "result",
but directly on a function call it tends to look like a mistake.
2014-07-10 06:02:40 +00:00
hannken
7bd94e9e7c Testing "v_usecount == 1" for exclusive reference will not always
work -- remove and test only readonly.
2014-05-30 08:40:09 +00:00
christos
02cb0c6eaf Introduce a selector function to the vfs vnode iterator so that we don't
need to vget() vnodes that we are not interested at, and optimize locking
a bit. Iterator changes reviewed by Hannken (thanks), the rest of the bugs
are mine.
2014-05-24 16:34:03 +00:00
hannken
42c8d67c49 Add a global vnode cache:
- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair.  This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41
2014-05-08 08:21:53 +00:00
maxv
23f76b6d00 An (un)privileged user can easily make the kernel dereference a NULL
pointer.

The kernel allows 'data' to be NULL; it's the fs's responsibility to
ensure that it isn't NULL (if the fs actually needs data).

ok christos@
2014-04-16 18:55:17 +00:00
christos
8750e04635 Check for bread errors before we do the size check. Otherwise we de-reference
NULL...
2014-04-01 14:28:17 +00:00
hannken
f3cf481632 - Make VI_XLOCK, VI_CLEAN and VI_LOCKSHARE private to kern/vfs_*.c.
- Make vwait() static.
- Add  vdead_check() to check a vnode for being or becoming dead.

Discussed on tech-kern.

Welcome to 6.99.38
2014-03-24 13:42:40 +00:00
hannken
6d285189fb Change all vfsops to use C99 designated initializers.
No functional changes intended.
2014-03-23 15:21:15 +00:00