summaryrefslogtreecommitdiff
path: root/fs
AgeCommit message (Collapse)Author
2 daysMerge tag 'xfs-fixes-7.4-rc4' of git://git.kernel.org:/pub/scm/fs/xfs/xfs-linuxLinus Torvalds
Pull xfs fixes from Carlos Maiolino: "Mostly this includes fixes for a few races, an ordering problem during init/teardown of proc/sysfs, missing locks, etc" * tag 'xfs-fixes-7.4-rc4' of git://git.kernel.org:/pub/scm/fs/xfs/xfs-linux: xfs: test for realtime and reflink under the pNFS locks xfs: don't enable DAX on zoned inodes xfs: restart faults racing with realtime flag changes xfs: take the MMAPLOCK in xfs_fileattr_set() xfs: refuse fallocate racing with realtime flag changes xfs: test for always COW after the dio write checks xfs: refuse writes to files racing with realtime inode flag changes xfs: test for reflink after the dio write checks xfs: properly order xfsstats proc/sysfs init and teardown xfs: remove unused variable in xrep_tempfile_copyin() xfs: remove unused variable in xchk_stats_estimate_bufsize() xfs: fix f_bfree underflow in statfs() xfs: wait for direct I/O before swapping extents xfs: break layouts before swapping extents iomap: don't punch delalloc under a dirty EOF block xfs: don't change the block map under a dirty folio xfs: flush the shifted range before changing the file xfs: don't skip the flush before shifting extents xfs: always call xfs_update_stable_writes in xfs_ioctl_setattr_xflags xfs: keep successful near rt allocations
2 daysMerge tag 'cifs-fixes-7.4-rc4' of https://git.manguebit.org/linuxLinus Torvalds
Pull smb client fixes from Paulo Alcantara: "The main ones are a server-triggerable use-after-free and two fixes that stop the client from accepting SMB2 responses and read data with a bad signature; the rest are a couple of busy-inode-on-unmount races and some metadata fixes. - Fix a use-after-free in the netfs write collector that a malicious or broken server can trigger by returning a write count larger than the request - Reject SMB2 responses whose signature fails verification instead of using them, so a tampered response on a signed connection is no longer accepted - Don't return read data whose signature failed verification when the read lands at the remote end of file - Fix a busy inode and dentry on unmount caused by a late oplock break queued after the workqueues were already flushed - Fix a busy dentry on unmount caused by a persistent-handle reopen racing the unmount - Fix creation and change time assignments in the SMB2 POSIX readdir path, which clobbered ctime and could give a hard link a separate in-memory inode - Normalise pre-epoch timestamps read from the server so stat no longer reports a garbled time - Fix DFS prefix paths being truncated on non-utf8 mounts, where path_consumed was applied in the wrong charset and the mount failed with -ENOENT" * tag 'cifs-fixes-7.4-rc4' of https://git.manguebit.org/linux: smb: client: don't use read data that failed signature verification smb: client: do not let the server grow a write subrequest smb: client: fix busy dentry on unmount from persistent handle reopen smb: client: fix busy dentry and inode on unmount from late oplock break smb: client: fail SMB2 responses with a bad signature smb: client: fix times assignments in cifs_posix_to_fattr() smb: client: fix negative timestamps being read from smb smb: client: convert path_consumed to mount charset units
3 daysMerge tag 'zonefs-7.4-rc4' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/zonefs Pull zonefs fixes from Damien Le Moal: - Avoid potentially opening the wrong file in the case of an overflow when converting a file names to an inode number (Guangshuo) - Handle potential overflow of RLIMIT_FSIZE (Ding) * tag 'zonefs-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/zonefs: zonefs: ignore RLIMIT_FSIZE above LLONG_MAX in zonefs_write_check_limits() zonefs: check multiplication overflow in zonefs_fname_to_fno()
4 daysMerge tag 'fuse-fixes-7.4-rc4' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse Pull fuse fixes from Miklos Szeredi: - Fix bugs reported by Sashiko - Fix a couple of issues introduced in this cycle - Misc bug fixes * tag 'fuse-fixes-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: limit name size in listxattr fuse: clear the old EOF tail before writeback-cache writes fuse: fix UBSAN warning in fuse_iomap_writeback_range() fuse: skip dcache instantiation for readdirplus names with embedded NUL fuse: preserve ENOTCONN after failed initialization and disconnect fuse: set dentry epoch before making the dentry visible fuse: advertise support for DAX mappings fuse: don't mark inode DAX without CONFIG_FS_DAX fuse: don't pass a NULL inode to fuse_inode_backing() on release virtiofs: zero the reply region of the argument buffer virtiofs: disable request timeout virtiofs: fix use-after-free of fs->tag on device removal fuse: derive short read EOF from the request offset selftests/fuse: test post-EOF page zeroing on copy_file_range() fuse: zero the partial EOF page in copy_file_range() fuse: fix possible UAF in fuse_direntplus_link() fuse: Use d_alloc_trylock() in fuse_direntplus_link()
4 dayszonefs: ignore RLIMIT_FSIZE above LLONG_MAX in zonefs_write_check_limits()Ding Feng
zonefs_write_check_limits() follows generic_write_check_limits() and has the same problem: it stores rlimit(RLIMIT_FSIZE), an unsigned long, in a loff_t, so a soft limit between 2^63 and RLIM_INFINITY is negative and every write fails with -EFBIG and raises SIGXFSZ. Keep the limit unsigned and apply it only when it is at most LLONG_MAX, as the generic helper now does. Fixes: ebfd68cd0c1e ("zonefs: Fix O_APPEND async write handling") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Frama-C Signed-off-by: Ding Feng <dingf3ng@gmail.com> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
4 daysfuse: limit name size in listxattrMiklos Szeredi
Limit the size of names to XATTR_NAME_MAX. Return -EIO to the listxattr() caller if the server exceeds this limit. Fixes: 92a8780e1136 ("[PATCH] FUSE - extended attribute operations") Cc: stable@vger.kernel.org Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
4 daysfuse: clear the old EOF tail before writeback-cache writesHungyu Lin
Buffered writeback-cache writes go through iomap_file_buffered_write(), but do not clear cached data between the old EOF and the write position. If a shared mapping dirtied the tail of the old EOF page, an extending write can expose those bytes as file contents instead of zeros. A later writeback can also send them to the server. Clear the gap under the existing inode lock before the buffered write. Use the same page-cache cleanup as fuse_perform_write() does for write-through writes, leaving the write range itself untouched. Fixes: 4d99ff8f12eb ("fuse: Turn writeback cache on") Cc: stable@vger.kernel.org Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
4 daysfuse: fix UBSAN warning in fuse_iomap_writeback_range()Shunbo Shi
In fuse_iomap_writeback_range() 'ap' is initialized to '&wpa->ia.ap' unconditionally, but 'wpa' (== data->wpa) is NULL when the writeback of the first folio of a batch starts: 'data' is zero-initialized in fuse_writepages() and fuse_launder_folio(), and fuse_writepages_send() resets data->wpa to NULL after every batch. Taking the address of a member of a NULL pointer is undefined behavior. The bogus initial value of 'ap' is never actually dereferenced: all uses are either guarded by 'if (wpa)' or run after 'ap' has been reassigned in the 'data->wpa == NULL' branch, where a new 'wpa' is allocated first. Still, the expression lets the compiler assume that 'wpa' is non-NULL for the whole function, which could break the 'if (wpa)' check below and turn the latent UB into a real NULL pointer dereference. This can be observed with a kernel built with -fsanitize=null (not part of the default CONFIG_UBSAN flag set) when writeback of an mmap dirty region is triggered, e.g. via msync()/fsync(): UBSAN: member access within null pointer of type 'struct fuse_writepage_args' Call Trace: __ubsan_handle_type_mismatch_v1+0x3f/0x50 fuse_iomap_writeback_range+0x79c/0xbd0 iomap_writepages+0x64/0x140 fuse_writepages+0xe0/0x260 do_writepages+0xaa/0x360 Initialize 'ap' to NULL when 'wpa' is NULL. With this change the warning above is gone while the writeback path is exercised identically. Signed-off-by: Shunbo Shi <shishunbo@cmss.chinamobile.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: skip dcache instantiation for readdirplus names with embedded NULJunyoung Jang
FUSE READDIRPLUS can pass a length-bearing qstr with an embedded NUL to d_splice_alias(). Unlike verify_dirent_name() in fs/readdir.c, this path can create a dentry whose d_name.len extends past the NUL. For such a name, strscpy() in inotify_handle_inode_event() and the fanotify name-copy helpers stop early. The kmalloc() and kvmalloc() event-name buffers retain uninitialized bytes within the recorded name length, which copy_event_to_user() and copy_fid_info_to_user() can expose. Some FUSE servers include a terminating NUL in namelen. Follow nfs_prime_dcache() in commit 78d04af4995a1 ("NFS: nfs_prime_dcache must validate the filename") by skipping dcache instantiation without failing getdents(). Return -EIO from fuse_direntplus_link() so parse_dirplusfile() sends FUSE_FORGET for the unused lookup reference and continues readdir. Fixes: 0b05b18381ee ("fuse: implement NFS-like readdirplus support") Cc: stable@vger.kernel.org Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com> Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com> Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: preserve ENOTCONN after failed initialization and disconnectHengyu Liang
Commit 794e811d1443 ("fuse: split out filesystem part of request sending") moved the INIT failure check into fuse_req_prep(), before the channel checks whether it is still connected. If a daemon closes /dev/fuse before replying to INIT, aborting the channel completes INIT with an error. stat() and open() on the mount then return ECONNREFUSED instead of the previous ENOTCONN. The same change occurs when INIT is rejected before the daemon closes the fd. Record INIT failure in the channel before publishing initialized, and check it in fuse_get_req() after waiting for initialization and checking for disconnection. This preserves ECONNREFUSED for failed INIT while the device remains open, and restores ENOTCONN after disconnection. Set the failure flag only while the channel is connected, since abort also marks it initialized to wake waiters after a successful INIT. Fixes: 794e811d1443 ("fuse: split out filesystem part of request sending") Cc: stable@vger.kernel.org Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: set dentry epoch before making the dentry visibleLeon Ming
fuse_lookup(), create_new_entry(), fuse_create_open() and fuse_direntplus_link() set the dentry epoch only after d_splice_alias() or d_instantiate() has made the dentry visible. A new dentry starts at epoch 0 and the connection at epoch 1, so in that window a concurrent lookup can find the dentry, fail fuse_dentry_revalidate() and d_invalidate() it. The original lookup then returns an unhashed dentry, and readlink() of /proc/self/fd/N on an O_PATH fd for it says "<path> (deleted)" for a file that exists. Anything that resolves real paths with open(O_PATH) + readlink() can pick up the bogus path; TypeScript's native compiler (tsgo) intermittently fails to find installed packages this way. It got much more common after commit 5a6baf204610 ("fuse: fix uninit-value in fuse_dentry_revalidate()") zeroed the initial epoch; before that, slab garbage usually passed the check. Set the epoch before the dentry is published, and keep setting it on any alias that d_splice_alias() returns; the dentry that loses to an alias is dropped without ever being visible, so setting it too is harmless. With 32 processes making concurrent first lookups of 6000 files on a fresh squashfuse_ll mount (UML, 16 CPUs), 1652 of 10.75M lookups came back "(deleted)" before this patch and none after. Fixes: 2396356a945b ("fuse: add more control over cache invalidation behaviour") Cc: stable@vger.kernel.org Signed-off-by: Leon Ming <leonming@meta.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: advertise support for DAX mappingsMiklos Szeredi
Reuse the FUSE_HAS_INODE_DAX flag, which previously was only used for the virtiofs case. The two uses are unrelated: for virtiofs the flag means that host memory can be mapped directly into the guest, while here it means that the server may back an inode with a dax device opened via FUSE_DEV_IOC_BACKING_OPEN. Gate the advertisement on IS_REACHABLE(CONFIG_DEV_DAX_FSDEV), which is what fuse_backing_open_file() requires before it accepts a dax device as backing; CONFIG_FS_DAX alone is not sufficient. Plain fuse servers should check both FUSE_HAS_INODE_DAX and FUSE_PASSTHROUGH_V2 before enabling passthrough dax support. Stop advertising FUSE_PASSTHROUGH(_V2) in the virtiofs case, which doesn't support passthrough mode. Note: FUSE_HAS_INODE_DAX flag in the INIT reply is ignored, so it's handled slightly differently from the virtiofs case. This is deliberate. The server needs to check both FUSE_PASSTHROUGH_V2 and FUSE_HAS_INODE_DAX before enabling DAX based extent map if it wants to bail or fall back to plain I/O mode on kernels not supporting this feature. A broken server that does not check the features yet sets FUSE_ATTR_DAX will result in an error on open. This is not backward compatible, since this flag was silently ignored previously, but unlikely to be an issue in real life. Fixes: 2fbe4586cff3 ("fuse: add support for opening dax device as backing") Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: don't mark inode DAX without CONFIG_FS_DAXMiklos Szeredi
fuse_init_inode() installs fuse_dax_aops and sets S_DAX for any regular file whose lookup reply carries FUSE_ATTR_DAX. Without CONFIG_FS_DAX, S_DAX is zero and IS_DAX() is constant false, so all of the checks that keep such inodes away from the page cache are compiled out: the "DAX inode without FOPEN_PASSTHROUGH" rejection in fuse_file_io_open(), the O_TRUNC check in fuse_open(), the truncate check in fuse_do_setattr(), the check in fuse_file_fallocate() and the one in fuse_passthrough_open(). The address space operations are installed regardless, so the inode ends up in caching I/O mode with aops that have neither ->read_folio nor ->readahead, and a buffered read, mmap fault or splice oopses on a NULL callback. Any user able to mount a fuse filesystem can trigger this. Only honor FUSE_ATTR_DAX if DAX can work at all. Fixes: 2fbe4586cff3 ("fuse: add support for opening dax device as backing") Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/bug/linux-bb232f07-d992-4dc6-a6c5-400e98e7133f Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: don't pass a NULL inode to fuse_inode_backing() on releaseOrkun Emin Sarı
cuse_release() and the error path of fuse_create_open() call fuse_prepare_release() with a NULL fuse_inode. Since commit bbe2d73a8231 ("fuse: don't assume ff->passthrough is set for FOPEN_PASSTHROUGH"), fuse_prepare_release() calls fuse_inode_backing(fi) whenever the open reply had FOPEN_PASSTHROUGH set, not only when ff->passthrough was set up. A CUSE server that sets FOPEN_PASSTHROUGH thus makes the kernel dereference a NULL pointer when the device is closed. Pass a NULL backing when there is no inode. fuse_passthrough_release() only prints it. Found with AI-assisted code review (Claude Code). Fixes: bbe2d73a8231 ("fuse: don't assume ff->passthrough is set for FOPEN_PASSTHROUGH") Signed-off-by: Orkun Emin Sarı <sariorkunemin@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysvirtiofs: zero the reply region of the argument bufferMiklos Szeredi
copy_args_to_argbuf() allocates one buffer for the fixed in- and out-args and fills only the in-arg part. The remainder is handed to the server as a device-writable buffer, and the server is under no obligation to write it: the used length it reports is its own claim and virtio_fs_verify_response() has nothing to cross-check it against. A reply that declares its full length without filling the buffer makes copy_args_from_argbuf() copy the uninitialized remainder to the caller, so a server that fails partway through writing a reply returns stale heap contents from e.g. fuse_statfs() or fuse_getxattr() instead of an error. Commit 5364d081125a ("virtiofs: validate fixed-output response length") covers the case where the declared length is short. Zero the reply region so that the remaining case yields zeroes rather than whatever the allocator last held. Only that region is zeroed; the in-arg part is overwritten by the copy below and the buffer can be as large as XATTR_SIZE_MAX. Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem") Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/bug/linux-f0d6d4a3-f5df-4f72-ab09-802e5aab49a6 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysvirtiofs: disable request timeoutMiklos Szeredi
The request timeout is implemented by aborting the connection: fuse_check_timeout() calls fuse_chan_abort(), which splices fpq->processing onto a local list and ends those requests. Ending a request wakes the waiting caller, which then drops the last reference and frees it. That is safe for /dev/fuse, where the request has already been copied out to userspace and nothing outside the kernel retains a pointer to it. It is not safe for virtiofs. virtio_fs_enqueue_req() passes the bare req as the virtqueue token, and the scatterlists point at req->in.h, req->out.h, req->argbuf and the request's folios; the device still owns all of that after the abort. When the device eventually completes the request, virtio_fs_requests_done_work() gets the freed req back from virtqueue_get_buf() and passes it to virtio_fs_verify_response() and virtio_fs_request_complete(), which dereference req->args - the caller's stack frame, long gone - and kfree() whatever req->argbuf now reads as. The device may also have written the reply into the freed request or into folios that have since been reused. This is precisely why virtio_fs_conn_destroy() drains all queues down to in_flight == 0 before calling fuse_conn_destroy(): once buffers are in a virtqueue, the only ways to reclaim them are to wait for completion or to reset the device. virtiofs already disables the other two paths that could abort a live connection, via ctx->no_control and ctx->no_force_umount; the timeout is the one that was left. Timeouts make little sense for virtiofs in the first place. A timeout is a guest-side reaction to a wedged host, and the guest has no recourse: it can neither take the buffers back nor make the host answer. So add fuse_conn::no_req_timeout for transports that cannot revoke a request once it has been handed to the server, set it from virtiofs, and use it to skip both fuse_init_server_timeout() and the FUSE_REQUEST_TIMEOUT negotiation flag. Skipping the former matters on its own: without it the fs/fuse/default_request_timeout sysctl would arm the timer even though FUSE_REQUEST_TIMEOUT was never offered to the server. Note that this is not a security issue. virtiofs inverts the usual fuse trust relationship - the server is the privileged, trusted side and the guest kernel is the untrusted one - so a server intent on corrupting guest memory has far more direct means at its disposal. Fixes: 0f6439f61a6e ("fuse: add kernel-enforced timeout option for requests") Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/bug/linux-8171ebf0-ef01-4ccd-943e-8633a8d54239 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysvirtiofs: fix use-after-free of fs->tag on device removalMiklos Szeredi
The virtio_fs object is refcounted via its kobject, so a mount can keep it alive well beyond the lifetime of the virtio device binding. The tag string, however, was allocated with devm_kmalloc() and is therefore freed by devres_release_all() as soon as the device is unbound, i.e. right after virtio_fs_remove() returns (see device_unbind_cleanup() in drivers/base/dd.c). virtio_fs_get_tree() looks up the instance, takes a kobject reference and then drops virtio_fs_mutex before doing the sleepable part of the mount (allocations, fuse_conn_init(), sget_fc()). A concurrent device removal can complete in that window: CPU 0 (mount) CPU 1 (remove) ------------- -------------- virtio_fs_get_tree() virtio_fs_find_instance() // reference taken, mutex dropped virtio_fs_remove() list_del_init(&fs->list); // driver core unbinds device // devres frees fs->tag virtio_fs_fill_super() mutex_lock(&virtio_fs_mutex); if (list_empty(&fs->list)) pr_info(... fs->tag); <-- use-after-free The virtio_fs object itself is still valid here, only its tag has been freed behind its back. Fix the lifetime mismatch at the source: allocate the tag with kmalloc() and free it from virtio_fs_ktype_release(), so that it lives exactly as long as the object embedding it. All probe error paths already drop the final kobject reference, so they are covered. Merely dropping the tag from the error message would paper over this instance while leaving a devres pointer embedded in an object that routinely outlives its device. The other readers of fs->tag are unaffected: tag_show() is fenced off by the kobject_del() in virtio_fs_remove(), the automatic KOBJ_REMOVE uevent is emitted from __kobject_del() while the device is still bound, and both virtio_fs_add_instance() and virtio_fs_find_instance() only walk instances still on virtio_fs_instances. Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem") Cc: <stable@vger.kernel.org> Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/bug/linux-0328b3a1-043b-468e-8425-6a613d91b5ef Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysfuse: derive short read EOF from the request offsetMiklos Szeredi
fuse_short_read() computed the new file size as folio_pos(ap->folios[0]) + num_read which assumes that the read started at the beginning of the first folio. That is not true in general: fuse_do_readfolio() may be asked to read part of a folio only, in which case it passes the offset within the folio in descs[0].offset and correctly adds it to the position of the request. If such a read came back short, the EOF derived from it would be descs[0].offset bytes too low and i_size would be truncated accordingly. fuse_send_readpages() made the same assumption for the position of the read request itself, even though fuse_copy_folios() fills the first folio starting at descs[0].offset. Neither is reachable today: sub-folio reads only originate from the iomap buffered write path, which requires fc->writeback_cache, and in that case fuse_short_read() does not update the size at all; readahead always starts on a folio boundary. Don't rely on that, though. Add fuse_folios_pos() to compute the position of the first byte covered by a folio array and use it for both read requests. Make fuse_short_read() take the fuse_io_args and derive EOF from ia->read.in.offset, i.e. the offset the request was actually sent with, so that the two can no longer disagree. fuse_do_readfolio() now keeps the attribute version in ia.read.attr_ver, as the readahead path already did. No functional change intended. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
5 daysMerge tag 'nfsd-7.4-1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux Pull nfsd fix from Chuck Lever: - Unlock the correct parent directory after CREATE crosses a mount * tag 'nfsd-7.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux: nfsd: unlock the locked parent after crossing a mount in CREATE
5 daysnfsd: unlock the locked parent after crossing a mount in CREATEorkunsari
Since commit f58a48389c14 ("nfsd: correctly handle CREATE of mounted-on files"), nfsd_proc_create() and nfsd3_create_file() call nfsd_cross_mnt() on the dentry returned by start_creating(). When the name refers to a file that has something mounted on it, nfsd_cross_mnt() replaces that dentry with the root of the mounted filesystem and drops its reference to the original one. The replacement is later passed to end_creating(), which unlocks the d_parent of the dentry it is given. That is the parent of the mount source, not the directory start_creating() locked, so the directory being created in is left locked and another directory's i_rwsem is released without being held. Do the crossing on a separate reference that is only used for fh_compose(), so that the dentry returned by start_creating() is the one passed to end_creating(). Only positive regular files are crossed, so the later checks on the child dentry give the same result. This was found by AI-assisted code review (Claude Code). The fix has been build-tested with W=1 only; no reproducer was run. Fixes: f58a48389c14 ("nfsd: correctly handle CREATE of mounted-on files") Signed-off-by: orkunsari <sariorkunemin@gmail.com> Link: https://patch.msgid.link/20261104-nfsd-cross-mnt-v1-1-5ec5fca0a553@gmail.com Signed-off-by: Chuck Lever <cel@kernel.org>
5 dayssmb: client: don't use read data that failed signature verificationSuyuan Wang
When smb2_readv_callback() finds a bad signature, it sets the error in rdata->result but leaves rdata->got_bytes alone. Further down, a short read that reaches the remote EOF clears the error again: size_t trans = rdata->subreq.transferred + rdata->got_bytes; if (trans < rdata->subreq.len && rdata->subreq.start + trans >= netfs_read_remote_i_size(inode)) { rdata->result = 0; and got_bytes is then added to subreq.transferred. So the last part of a file, or all of a small one, is returned even though its signature is wrong. Clearing got_bytes is not enough on its own. If the read starts at or past the cached remote size, for example because the file has grown on the server since the size was last fetched, the check above still matches and the error turns into EOF, or into a zero-filled tail when NETFS_SREQ_CLEAR_TAIL is set. Clear got_bytes when the signature check fails, as the retry path in the same function already does, and only treat a short read as hitting the remote EOF when the read itself succeeded. That is what commit 1da29f2c39b6 ("netfs, cifs: Fix handling of short DIO read") describes: "clear the error if a short read occurred without error and the read-to file position is now at the remote inode size". Found with a static analysis tool and checked by hand. Fixes: 1da29f2c39b6 ("netfs, cifs: Fix handling of short DIO read") Cc: stable@vger.kernel.org Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
5 dayssmb: client: do not let the server grow a write subrequestozgun kultekin
smb2_writev_callback() takes the byte count from the SMB2 WRITE response, masks it with 0xFFFF if it is larger than the request (for old OS/2 servers), and then copies it into wdata->subreq.len. A server can return a count that is still larger than the request after the mask, for example 0x8002 for a 5-byte write or 0xFFFF for a 4 KiB write, and the subrequest then covers data that was never sent. netfs uses the subrequest length to decide how far the write collector may advance. With a grown subrequest the collector moves collected_to past the data that was issued: netfs_writeback_unlock_folios() walks folio_queue slots that were never filled, and rolling_buffer_delete_spent() frees folio_queue segments that later in-flight subrequests still use. This is a use-after-free that a malicious or broken server triggers from an ordinary write: BUG: KASAN: slab-use-after-free in netfs_limit_iter+0xed4/0x1040 Read of size 1 at addr ff11000010561511 by task kworker/u8:4/63 Workqueue: events_unbound netfs_write_collection_worker netfs_limit_iter+0xed4/0x1040 netfs_retry_writes+0x1410/0x1e90 netfs_write_collection+0x2647/0x3880 netfs_write_collection_worker+0x1cd/0x3e0 Allocated by task 141: netfs_folioq_alloc+0x39a/0x470 rolling_buffer_init+0x29/0xc0 netfs_create_write_req+0x12f/0x840 Freed by task 42: rolling_buffer_delete_spent+0xb1/0x220 netfs_write_collection+0x1f62/0x3880 Never change the subrequest length from the response. If the count is still larger than the request after the mask, fail the write with -EIO and record it with a new write_overlarge trace point, like the read path does with read_overlarge. A short count still returns -ENOSPC as before. The folio_queue form of the use-after-free exists since commit cd0277ed0c18 ("netfs: Use new folio_queue data type and iterator instead of xarray iter"). Fixes: 3ee1a1fc3981 ("cifs: Cut over to using netfslib") Cc: stable@vger.kernel.org Signed-off-by: ozgun kultekin <ozgunkultekin@gmail.com> Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
5 dayssmb: client: fix busy dentry on unmount from persistent handle reopenSiddharth Chintamaneni
During unmount, cifs_kill_sb() waits on cifs_sb->outstanding_rreq for in-flight netfs I/O requests and oplock breaks to complete before flushing serverclose_wq and fileinfo_put_wq. While cifs_kill_sb() is waiting on outstanding_rreq, any cifsFileInfo referenced by an in-flight request (req->cfile) remains on tcon->openFileList. On a mount using persistent handles, if a reconnect runs on cifsiod_wq during this window, smb2_reconnect_server() calls cifs_reopen_persistent_handles(), which walks tcon->openFileList and takes a new reference on open_file via cifsFileInfo_get() to reopen the handle over the network: Thread 1 (umount) Thread 2 (cifsiod_wq) Thread 3 (workers) ----------------- --------------------- ------------------ cifs_kill_sb() wait(outstanding_rreq) [blocks: rreq == 1] smb2_reconnect_server() cifs_reopen_persistent_handles() finds open_file on list cifsFileInfo_get(open_file) [cfile->count: 1 -> 2] cifs_reopen_file() cifs_free_request() cifsFileInfo_put() [cfile->count: 2 -> 1] dec(outstanding_rreq) [wakes: rreq == 0] flush(serverclose_wq) flush(fileinfo_put_wq) kill_anon_super(sb) -> generic_shutdown_super() BUG: Dentry still in use (1) VFS: Busy inodes after unmount! Fix this by incrementing cifs_sb->outstanding_rreq when cifs_reopen_persistent_handles() takes a reference on open_file and decrementing it after cifsFileInfo_put(open_file), so wait_var_event() in cifs_kill_sb() waits for any in-progress persistent handle reopen to finish and queue its final put before draining fileinfo_put_wq. Fixes: 340cea84f691 ("cifs: open files should not hold ref on superblock") Cc: stable@vger.kernel.org Reported-by: Adam Kim <adamkim@microsoft.com> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
5 dayssmb: client: fix busy dentry and inode on unmount from late oplock breakSiddharth Chintamaneni
During unmount, cifs_kill_sb() flushes cifsoplockd_wq and deferredclose_wq before waiting on cifs_sb->outstanding_rreq for in-flight netfs I/O requests to finish their cleanup_work in cifs_free_request(). While cifs_kill_sb() is waiting on outstanding_rreq, any cifsFileInfo referenced by an in-flight request (req->cfile) still has cfile->count >= 1 and remains on tcon->openFileList. If the SMB server sends a lease or oplock break for that file during this window, the demultiplex thread (cifsd) finds cfile on tcon->openFileList and calls cifs_queue_oplock_break(cfile), which takes a new reference on cfile and queues cfile->oplock_break onto cifsoplockd_wq after cifsoplockd_wq was already flushed: Thread 1 (umount) Thread 2 (cifsd) Thread 3 (workers) ----------------- ---------------- ------------------ cifs_kill_sb() flush(cifsoplockd_wq) flush(deferredclose_wq) wait(outstanding_rreq) [blocks: rreq == 1] SMB2 Lease Break finds cfile on list cifs_queue_oplock_break() queue(cifsoplockd_wq) cifsFileInfo_get(cfile) [cfile->count: 1 -> 2] cifs_oplock_break() ihold(inode) cifs_free_request() cifsFileInfo_put() [cfile->count: 2 -> 1] dec(outstanding_rreq) [wakes: rreq == 0] flush(serverclose_wq) flush(fileinfo_put_wq) kill_anon_super(sb) -> generic_shutdown_super() BUG: Dentry still in use (1) VFS: Busy inodes after unmount! Furthermore, cifs_oplock_break() itself holds the inode via ihold() after dropping cfile and may initiate writeback via filemap_fdatawrite(), spawning new netfs I/O requests. Fix this by counting queued oplock breaks in cifs_sb->outstanding_rreq from when cifs_queue_oplock_break() queues the work until cifs_oplock_break() finishes, so wait_var_event() in cifs_kill_sb() waits for both in-flight I/O requests and any late oplock breaks to complete. Fixes: 340cea84f691 ("cifs: open files should not hold ref on superblock") Cc: stable@vger.kernel.org Reported-by: Adam Kim <adamkim@microsoft.com> Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
6 dayssmb: client: fail SMB2 responses with a bad signatureSuyuan Wang
smb2_check_receive() checks the response signature when signing is on, but a failed check is only logged: rc = smb2_verify_signature(&rqst, server); if (rc) cifs_server_dbg(VFS, "SMB signature verification returned ...", rc); ... return map_smb2_to_linux_error(mid->resp_buf, log_error); The status from the response is returned as usual, and the caller goes on to use a response whose signature is wrong. This is the path for synchronous and compound requests and for smb2_writev_callback(). On a signed but unencrypted connection, anyone who can modify the traffic can change e.g. a directory listing or file attributes, and the client accepts it. Return the verification error instead. That alone is not enough for compound_send_recv(), which still hands the response buffer to the caller after check_receive() fails. smb2_compound_op() then maps the status from that buffer again and copies the payload out, and other callers look at the buffer on error too, e.g. smb2_open_file() parses a symlink target out of a STATUS_STOPPED_ON_SYMLINK response. So also mark the mid MID_RESPONSE_MALFORMED, and have compound_send_recv() handle it like a mid in a bad state: mark the earlier mids cancelled, so that a CREATE which did succeed gets its handle closed, and don't pass any response on. Unlike the SMB1 fix in commit dc96f01d54cc ("smb: client: terminate session upon failed client required signing"), don't reconnect: this runs in the thread that sent the request, and only cifsd should call cifs_reconnect(). And fail the request whichever side required signing, since a response with a bad signature can't be trusted either way. Found with a static analysis tool and checked by hand. Reported-by: Daniel Birtwhistle <daniel.birtwhistle@gehealthcare.com> Closes: https://lore.kernel.org/linux-cifs/SN4PR22MB28883DAF57E0B4D4BFB1C22AEEC42@SN4PR22MB2888.namprd22.prod.outlook.com/ Fixes: 3c1bf7e48e9e ("CIFS: Enable signing in SMB2") Cc: stable@vger.kernel.org Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
6 dayszonefs: check multiplication overflow in zonefs_fname_to_fno()Guangshuo Li
The change referenced by the Fixes tag added overflow checking for the addition used while converting a zone file name to a zone number. However, the digit value and decimal shift are still computed with unchecked signed long multiplications. For sufficiently long numeric names, shift or digit can overflow before check_add_overflow() sees the value, leaving the parser with an already corrupted intermediate result. Check the digit and shift multiplications as well. Only advance the shift when another digit remains, so valid boundary values are not rejected due to an unused final shift update. Fixes: 3a8389d42bdf ("zonefs: handle integer overflow in zonefs_fname_to_fno") Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
6 daysMerge tag 'mm-nonmm-hotfixes-stable-2026-11-18-00-06' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull non-MM updates from Andrew Morton: - "get_maintainer: stop sending every patch to LKML" (Konstantin Ryabitsev): Make THE REST a fallback when no usable subsystem list matches and update the submission guide. This avoids routine copies to LKML while retaining a mailing list for otherwise unmatched patches. - On local OCFS2 mounts, a failed shared mmap write fault now delivers SIGBUS instead of hitting BUG_ON(). Journal shutdown is serialized with inode cleanup, and checkpoint waiters no longer use a queue embedded in the journal being freed. - Queued dlmfs lock work now keeps the superblock active through its final iput(), avoiding a use-after-free during unmount. The OCFS2 locking_state debugfs iterator follows its live cursor instead of list links copied from a lock resource which may have been freed during a read-only remount. - Fault-injection boot parameters no longer call code which allocates memory and schedules work before slab and workqueues are initialized, fixing a boot failure. * tag 'mm-nonmm-hotfixes-stable-2026-11-18-00-06' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: MAINTAINERS: DRM DRIVERS AND MISC GPU PATCHES MAINTAINERS: update Andrea Cervesato's email for LTP mailmap: update email address for Sai Teja Aluvala mailmap: add an alias for Alex Elder mailmap: update entry for Guodong Xu mailmap: add entries for Ridong Chen mailmap: add Wang Yibo's work email address mailmap: add entry for Beat M. Liechti mailmap: update email address for Naman Jain mailmap: add entries for Luiz Capitulino mailmap: add entries for Miaoqing Pan mailmap: update Mika Westerberg's email address mailmap: update email address for Bradley Morgan docs: submitting-patches: make LKML a list of last resort again get_maintainer: only use THE REST as a fallback ocfs2: fix kernel BUG in ocfs2_page_mkwrite() when write_end fails fault-inject: fix boot failure with fault injection boot parameters ocfs2: advance locking_state through the live cursor ocfs2/dlmfs: keep the superblock alive during lock work ocfs2: serialize inode journal access with shutdown
6 daysMerge tag 'mm-hotfixes-stable-2026-11-17-19-55' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull MM fixes from Andrew Morton: - "maple_tree fixes for 7.3" (Liam R. Howlett): Fix an RCU reader NULL dereference when the tree is emptied during a walk, including /proc/PID/maps racing with munmap(). Add tests and make debug WARN and BUG checks report failures properly - "mm/kasan: Detect double-free involving kfree_rcu_sheaf()" (Kuniyuki Iwashima): Detect double-free when an object enters an RCU sheaf. KASAN could previously miss it until the object was reused, leading to a later free of a live object. Add KUnit tests for the different free orders - "mm: Fix page-table teardown during memory hot-remove" (Muchun Song): Balance page-table constructors and destructors when hot-remove frees tables on x86-64, RISC-V and arm64. This fixes NR_PAGETABLE accounting for tables with and without constructors - "mm/damon: fix watermark state, kunit pid leak and selftest fake pass" (SJ Park): Recompute watermark wait state when DAMON schemes are removed, so kdamond resumes monitoring. Fix a pid reference leak in KUnit and a selftest that reports a skipped run as a pass - An XArray iterator could step backwards when a large page-cache entry was split, sending filemap_map_pages() outside the PTE page it locked. The XArray correction and a filemap bound check prevent out-of-bounds accesses and use-after-free. Another XArray fix prevents lockless walkers from following a parent pointer into a freed node - Userfaultfd now validates the whole write-protection range before changing any VMA, avoiding partial unprotect without waking blocked faults. Failed unmaps now abort queued UFFD_EVENT_UNMAPs; previously they could report a nonexistent unmap, leak the userfaultfd context and leave later operations returning -EAGAIN. A fork fix clears stale uffd PTE bits if the new context is released before its event is read - Moving the hugetlbfs inode trace event before RCU freeing avoids a use-after-free of its superblock. Shmem swapin no longer retries forever on reused swap slots containing a mismatched large swap-cache folio. Swapoff also avoids a cluster-list loop that can soft-lock reclaim and leave swapoff hung - Weighted interleave recalculation now uses one node set throughout, avoiding a divide-by-zero during memory hotplug. Hwpoison holds the folio lock when inspecting its mapping and no longer leaks a folio reference; it also updates poison statistics before notifying rasdaemon through a trace event - Cross-node migration now moves NR_FILE_THPS and NR_KERNEL_FILE_PAGES with page-cache folios, preventing per-node and memcg-node accounting from retaining stale counts or underflowing after the folios are freed * tag 'mm-hotfixes-stable-2026-11-17-19-55' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (27 commits) xarray: fix index jumping backwards in xas_find() userfaultfd: validate the whole range before changing write protection maple_tree: update internal warning and bug_on code maple_tree: test emptying tree while RCU reading maple_tree: fix rcu reader NULL dereference after the tree is emptied mm/vma: read anon_vma carefully in validate_mm() hugetlbfs: move hugetlbfs_free_inode tracepoint to ->destroy_inode() selftests/damon/sysfs_memcg_path_leak: define ksft_skip mm/damon/tests/sysfs-kunit: fix leaked pid reference in add_targets test mm/damon/core: reset watermark wait state on each iteration mm/filemap: stop fault-around when the walk steps back mm: memory-failure: update statistics before emitting the trace event mm/vma: undo userfaultfd unmap preparation when unmapping fails userfaultfd: clear uffd state in child PTEs if uffd is released during fork mm/memory-failure: fix folio refcount leak and min_order_for_split() locking mm/shmem: fix swapin livelock on a mismatched large swap cache folio mm/mempolicy: use one node set for interleave weights xarray: clear the new head's parent before freeing the old head arm64/mm: fix destructor for unconstructed hotplug page tables riscv/mm: fix missing destructor for hotplug PUD tables ...
6 daysMerge tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linuxLinus Torvalds
Pull fscrypt fix from Eric Biggers: "Fix a NULL dereference that was theoretically possible if FS_IOC_SETFLAGS was called to set the casefold flag on an encrypted directory concurrently with its encryption key being set up" * tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux: fscrypt: Initialize ->ci_master_key before publication
6 daysocfs2: fix kernel BUG in ocfs2_page_mkwrite() when write_end failsZhiyuan Zhang
syzbot reported a kernel BUG in the ocfs2 write fault path: (syz.0.17,5578,0):ocfs2_write_end_nolock:1945 ERROR: status = -30 kernel BUG at fs/ocfs2/mmap.c:106! Call Trace: do_page_mkwrite+0x147/0x310 mm/memory.c:3879 do_shared_fault mm/memory.c:6145 [inline] handle_mm_fault+0x1a53/0x3750 mm/memory.c:6943 __ocfs2_page_mkwrite() calls ocfs2_write_begin_nolock() and then ocfs2_write_end_nolock(), and uses BUG_ON() to assert that the latter returns the full length. But ocfs2_write_end_nolock() can fail: since commit 7f27ec978b0e ("ocfs2: call ocfs2_journal_access_di() before ocfs2_journal_dirty() in ocfs2_write_end_nolock()") it gets journal access to the inode buffer again, because the handle may have been restarted since ocfs2_write_begin_nolock(). That fails with -EROFS or -EIO once the journal has been aborted or jbd2 has seen write errors on the device. The syzbot reproducer gets there by shrinking the backing loop device to zero with LOOP_SET_STATUS while writing to a shared file mapping. Handle the failure instead of crashing. ocfs2_write_end_nolock() leaves the mmap folio locked, because ocfs2_unlock_folios() skips it when w_target_locked is set so that it can be returned with VM_FAULT_LOCKED, and do_page_mkwrite() does not unlock it either when ->page_mkwrite() returns an error. So unlock it and fail the fault; the faulting task gets SIGBUS, like for the other errors in this function. For an mmap write ocfs2_write_end_nolock() returns either len or a negative errno: inline data has already been converted to extents by ocfs2_write_begin_nolock(), and copied is equal to len. The BUG matters for local mounts, where the filesystem is expected to go read-only and keep running after a journal abort. On clustered mounts ocfs2_abort() panics the node anyway as soon as it notices the aborted journal. Link: https://lore.kernel.org/20261111023444.22688-1-zhiyuanzhang912@gmail.com Fixes: 7f27ec978b0e ("ocfs2: call ocfs2_journal_access_di() before ocfs2_journal_dirty() in ocfs2_write_end_nolock()") Signed-off-by: Zhiyuan Zhang <zhiyuanzhang912@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reported-by: <syzbot+42984127d45ad96219de@syzkaller.appspotmail.com> Closes: https://syzkaller.appspot.com/bug?extid=42984127d45ad96219de Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Heming Zhao <heming.zhao@suse.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: yangwenfang <vicky.yangwenfang@huawei.com> Cc: <stable@vger.kernel.org> fs/ocfs2/mmap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
6 daysocfs2: advance locking_state through the live cursorCen Zhang
locking_state copies each lock resource under ocfs2_dlm_tracking_lock so its containing inode or quota object can be freed during the dump. The copied l_debug_list pointers do not have that lifetime protection. Yet ocfs2_dlm_seq_next() follows them to find the next record. Remounting read-only can free a quota-info object while a debugfs read is between the snapshot and the next iterator callback: locking_state reader Quota suspension -------------------- ---------------- snapshot current lock resource copy l_debug_list.next remove next resource from live list free quota-info object seq_next(): follow copied link read freed lock resource Advance through the live dummy cursor instead. List removal updates its links under the tracking lock. Position it after the resource being copied before releasing the lock, and never walk the snapshot's links. Reuse the per-open snapshot for a nonzero seq_start() position, including read continuation and buffer retries. Rewind the live cursor only when seq_file starts at index zero; seq_lseek() traverses from there through seq_next(). Clear the snapshot's l_ops marker at end of list so later reads remain at EOF. This avoids replaying the list prefix under the tracking lock on each read, without adding a new cursor or position field. KASAN report as below: BUG: KASAN: slab-use-after-free in ocfs2_dlm_next_res.isra.0+0x1b1/0x1d0 Read of size 8 at addr ffff888117ea9838 by task python3/489 CPU: 3 UID: 0 PID: 489 Comm: python3 Not tainted 7.3.0-rc4-next-20260921-pmb-bt-functional-v1+ #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? ocfs2_dlm_next_res.isra.0+0x1b1/0x1d0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20e/0x420 ? ocfs2_dlm_next_res.isra.0+0x1b1/0x1d0 kasan_report+0xe0/0x110 ? ocfs2_dlm_next_res.isra.0+0x1b1/0x1d0 ocfs2_dlm_next_res.isra.0+0x1b1/0x1d0 ? __pfx_ocfs2_dlm_next_res.isra.0+0x10/0x10 ? __pfx_do_raw_spin_lock+0x10/0x10 ocfs2_dlm_seq_next+0xb8/0x4c0 ? srso_alias_return_thunk+0x5/0xfbef5 seq_read_iter+0x92f/0x1110 ? srso_alias_return_thunk+0x5/0xfbef5 seq_read+0x362/0x5a0 ? __pfx_seq_read+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? selinux_file_permission+0x11d/0x540 full_proxy_read+0x11f/0x180 ? __pfx_full_proxy_read+0x10/0x10 vfs_read+0x1a0/0xc20 ? srso_alias_return_thunk+0x5/0xfbef5 ? kmem_cache_free+0x242/0x580 ? __pfx_vfs_read+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? putname+0x93/0xe0 ? srso_alias_return_thunk+0x5/0xfbef5 ? do_sys_openat2+0x12a/0x1b0 ? __pfx_do_sys_openat2+0x10/0x10 ksys_read+0x111/0x200 ? __pfx_ksys_read+0x10/0x10 ? irqentry_exit+0xbe/0x820 ? srso_alias_return_thunk+0x5/0xfbef5 ? trace_hardirqs_on_prepare+0x11d/0x150 do_syscall_64+0x114/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f0266dbb687 Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff RSP: 002b:00007ffccf76fc40 EFLAGS: 00000202 ORIG_RAX: 0000000000000000 RAX: ffffffffffffffda RBX: 00007f0266d27780 RCX: 00007f0266dbb687 RDX: 0000000000000001 RSI: 00007f0266a53200 RDI: 0000000000000004 RBP: 00007f0266d27700 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000001 R13: 00007f0266a53200 R14: 0000000000000004 R15: 00007f0266b651e0 </TASK> Allocated by task 547: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x28d/0x610 ocfs2_local_read_info+0x181/0x1580 dquot_load_quota_sb+0x68b/0x1000 dquot_load_quota_inode+0x227/0x3e0 ocfs2_enable_quotas+0x27c/0x520 ocfs2_fill_super+0x21f9/0x38f0 get_tree_bdev_flags+0x35d/0x5f0 vfs_get_tree+0x93/0x320 fc_mount+0x1d/0x200 path_mount+0x592/0x1e00 __x64_sys_mount+0x24b/0x2d0 do_syscall_64+0x114/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 577: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x308/0x580 ocfs2_local_free_info+0x47b/0x800 dquot_disable+0x5d9/0x17a0 ocfs2_susp_quotas.isra.0+0x22c/0x2b0 ocfs2_reconfigure+0x284/0xd00 reconfigure_super+0x3ca/0xa70 path_mount+0x16ae/0x1e00 __x64_sys_mount+0x24b/0x2d0 do_syscall_64+0x114/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff888117ea9800 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 56 bytes inside of freed 1024-byte region [ffff888117ea9800, ffff888117ea9c00) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x117ea8 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000040(head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000040 ffff888100042dc0 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0200000000000040 ffff888100042dc0 dead000000000100 dead000000000122 head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888117ea9700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff888117ea9780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff888117ea9800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff888117ea9880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff888117ea9900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Link: https://lore.kernel.org/pm-ocfs2-objects-candidate-0053-v7-ec41d4bbd38bb4d795a8@gmail.com Fixes: ccd979bdbce9 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem") Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Suggested-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Heming Zhao <heming.zhao@suse.com> Cc: Jia-Ju Bai <baijiaju1990@gmail.com> Cc: <jjzuming@gmail.com> Cc: <stable@vger.kernel.org> fs/ocfs2/dlmglue.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
6 daysocfs2/dlmfs: keep the superblock alive during lock workCen Zhang
Queued dlmfs lock work holds an inode reference, but no active reference to its superblock. The workqueue is drained on module exit rather than on each dlmfs unmount, and an inode reference does not stop superblock shutdown: generic_shutdown_super() reports the busy inode and goes on. DLM callback / worker Unmount --------------------- ------- queue lock work; igrab(inode) worker delayed drop last active superblock ref kill_anon_super() report the busy inode free the superblock finish lock work iput(inode) access the inode's freed superblock Flushing the workqueue from a dlmfs kill_sb would not be enough: a blocking AST can queue new work for an inode that is still alive after the flush and before eviction, and that work again holds only an inode reference. Take an active superblock reference before acquiring the queued inode reference, with the atomic_inc_not_zero() on s_active that grab_super() and the NFS and procfs superblock walkers use. Decline to queue if the superblock is already shutting down; the inode is then being evicted and user_dlm_destroy_lock() tears the lock down. The existing l_lock and USER_LOCK_QUEUED flag serialize this with other queue attempts. Each execution drops its inode reference before releasing the active superblock reference, outside l_lock. If that releases the last active reference, the unmount completes on the worker; it only waits for DLM replies and never for this workqueue. Only the relevant frames of the report are kept: Oops: general protection fault, probably for non-canonical address 0xfbd59c0000000026: 0000 [#1] SMP KASAN NOPTI KASAN: maybe wild-memory-access in range [0xdead000000000130-0xdead000000000137] Workqueue: user_dlm user_dlm_unblock_lock RIP: 0010:iput+0x246/0xc10 Call Trace: <TASK> user_dlm_unblock_lock+0x503/0xa50 process_one_work+0x9a8/0x1b40 worker_thread+0x65c/0xe40 </TASK> Link: https://lore.kernel.org/pm-ocfs2-objects-candidate-0054-v6-c3887cceae3b039e591e@gmail.com Fixes: 8df08c89c668 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem") Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Heming Zhao <heming.zhao@suse.com> Cc: Jia-Ju Bai <baijiaju1990@gmail.com> Cc: <jjzuming@gmail.com> Cc: <stable@vger.kernel.org> fs/ocfs2/dlmfs/userdlm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
6 daysocfs2: serialize inode journal access with shutdownCen Zhang
The downconvert thread can run inode cleanup until ocfs2_dlm_shutdown() stops it, but unmount shuts down the journal earlier. A final dentry post-unlock put can therefore enter ocfs2_clear_inode() while the journal is being destroyed. ocfs2_ci_fully_checkpointed() loads osb->journal before taking trans_inc_lock. Journal shutdown neither takes that lock for removal nor waits for the downconvert thread before freeing the journal: Downconvert thread Unmount ------------------ ------- dentry post-unlock; final iput() ocfs2_checkpoint_inode() load osb->journal ocfs2_journal_shutdown() free journal; clear pointer read the transaction ID The checkpoint wait queue is embedded in that journal, and the final jbd2_journal_release_jbd_inode() also needs its JBD2 journal to remain alive for the whole call. Protecting only the pointer load would leave those longer uses unprotected. Read and clear osb->journal under trans_inc_lock when checking checkpoint progress. Treat a removed journal as checkpointed. Move checkpoint waiters to the existing mount-owned checkpoint_event and wake it after checkpoint progress and journal removal, so the queue outlives the journal. The commit thread also waits there and rechecks its condition when woken. Serialize the final JBD2 inode release against JBD2 destruction and the journal free with a mount-owned rw_semaphore. Take the write side only after stopping the commit thread, and drop it before the journal inode's final iput(), whose cleanup can take the read side. Inode cleanup holds the read side only around the JBD2 release, outside checkpoint waits and DLM lock teardown. KASAN report as below: Oops: general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077] CPU: 0 UID: 0 PID: 587 Comm: ocfs2dc-33CAF04 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:ocfs2_clear_inode+0x8ae/0x1630 Code: fc ff df 48 c1 ea 03 80 3c 02 00 0f 85 27 0c 00 00 49 8d 7d 70 48 8b 43 c8 48 ba 00 00 00 00 00 fc ff df 48 89 f9 48 c1 e9 03 <80> 3c 11 00 0f 85 f0 0b 00 00 49 3b 45 70 0f 88 62 03 00 00 e8 49 RSP: 0018:ffff888118d3f878 EFLAGS: 00010212 RAX: 0000000000000001 RBX: ffff88811a5edc60 RCX: 000000000000000e RDX: dffffc0000000000 RSI: 0000000000000001 RDI: 0000000000000070 RBP: ffff888116134000 R08: 0000000000000001 R09: 0000000000000001 R10: ffffffff8965765f R11: 0000000000000001 R12: ffff88811a5ed400 R13: 0000000000000000 R14: ffff88811a5edbf8 R15: ffff88811a5ed408 FS: 0000000000000000(0000) GS:ffff8881fd4dc000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ff35b66f2c0 CR3: 00000001092ae005 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: <TASK> ? __pfx_ocfs2_clear_inode+0x10/0x10 ? __pfx_ocfs2_inode_is_valid_to_delete+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __lock_acquire+0x5a3/0x2140 ocfs2_evict_inode+0x1ed/0x11e0 ? inode_wait_for_writeback+0x14c/0x330 ? __pfx_ocfs2_evict_inode+0x10/0x10 ? lock_acquire+0x190/0x300 ? srso_alias_return_thunk+0x5/0xfbef5 ? find_held_lock+0x2b/0x80 ? evict+0x347/0x9f0 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x290 ? _raw_spin_unlock+0x23/0x40 ? __pfx_ocfs2_evict_inode+0x10/0x10 evict+0x38b/0x9f0 ? __pfx_evict+0x10/0x10 ? lock_acquire+0x190/0x300 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x290 ? __pfx_inode_just_drop+0x10/0x10 iput+0x680/0xb80 ocfs2_dentry_lock_put+0xc2/0x110 ? __pfx_ocfs2_dentry_post_unlock+0x10/0x10 ocfs2_process_blocked_lock+0x1fb/0x420 ? __pfx_ocfs2_process_blocked_lock+0x10/0x10 ? __pfx_pmbd_probe_hit_cookie+0x10/0x10 ? lock_release+0xc8/0x290 ? srso_alias_return_thunk+0x5/0xfbef5 ? lockdep_hardirqs_on_prepare+0xeb/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ocfs2_downconvert_thread+0x32b/0x780 ? do_raw_spin_lock+0x130/0x270 ? __pfx_ocfs2_downconvert_thread+0x10/0x10 ? __kthread_parkme+0xc1/0x220 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x290 ? __pfx_autoremove_wake_function+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? __kthread_parkme+0x177/0x220 ? __pfx_ocfs2_downconvert_thread+0x10/0x10 kthread+0x351/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf70 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- Link: https://lore.kernel.org/pm-ocfs2-objects-candidate-0004-v8-dbcb8f80b8df476084d6@gmail.com Fixes: da5e7c87827e ("ocfs2: cleanup journal init and shutdown") Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Heming Zhao <heming.zhao@suse.com> Cc: Jia-Ju Bai <baijiaju1990@gmail.com> Cc: <jjzuming@gmail.com> Cc: <stable@vger.kernel.org> fs/ocfs2/inode.c | 17 +++++++++-------- fs/ocfs2/journal.c | 30 ++++++++++++++++++++++-------- fs/ocfs2/journal.h | 17 +++++++++-------- fs/ocfs2/ocfs2.h | 1 + fs/ocfs2/super.c | 1 + 5 files changed, 42 insertions(+), 24 deletions(-)
6 dayssmb: client: fix times assignments in cifs_posix_to_fattr()koraynilay
Currently cifs_posix_to_fattr() wrongly sets SMB's CreationTime to fattr->cf_ctime. Fix this by setting fattr->cf_createtime to SMB's CreationTime and fattr->cf_ctime to SMB's ChangeTime, matching the behaviour of __dir_info_to_fattr(). This patch also fixes a few related issues reported by sashiko on another patch (see Sashiko Link tag). Reproducers for these bugs, with /tmp as the local filesystem folder exported as [test] in ksmbd.conf and /mnt as the smb folder mounted with mount -t cifs: mount -t cifs //127.0.0.1/test /mnt -o username=ciao,password=c,posix Issue 1: ctime clobbered by CreationTime during readdir mkdir -p /mnt/dir touch /mnt/dir/file sleep 4 chmod 644 /mnt/dir/file stat -c "ctime and btime before readdir: %Z %W" /mnt/dir/file ls -lc /mnt/dir > /dev/null stat -c "ctime and btime after readdir: %Z %W" /mnt/dir/file stat -c "ctime and btime on disk: %Z %W" /tmp/dir/file output before the fix, notice how ctime is the same as btime after the readdir, while it's 4 seconds ahead (because of the sleep 4) before the readdir (on disk timestamps are not touched): ctime and btime before readdir: 1794842068 1794842064 ctime and btime after readdir: 1794842064 1794842064 ctime and btime on disk: 1794842068 1794842064 output after the fix: ctime and btime before readdir: 1794842908 1794842904 ctime and btime after readdir: 1794842908 1794842904 ctime and btime on disk: 1794842908 1794842904 Issue 2: btime and ptime wiped out by readdir [ no reproducer as it only happens after the linked patch series is applied, since it needs cifs_i->createtime = fattr->cf_createtime in cifs_fattr_to_inode() ] Issue 3: in-memory inode aliasing (flock bypass on hardlink via readdir) mkdir -p /mnt/dir1 /mnt/dir2 echo "test" > /mnt/dir1/h1 ln /mnt/dir1/h1 /mnt/dir2/h2 exec 3< /mnt/dir1/h1 flock -x -n 3 # get exclusive lock ls /mnt/dir2 > /dev/null exec 4< /mnt/dir2/h2 flock -x -n 4 if [ $? -eq 0 ];then echo "acquired: duplicate in-memory inode" else echo "blocked: same inode" fi output before the fix: acquired: duplicate in-memory inode output after the fix: blocked: same inode Fixes: 3d519bd1269f ("cifs: plumb smb2 POSIX dir enumeration") Cc: stable@vger.kernel.org Reported-by: Sashiko <sashiko-bot@kernel.org> Link: https://sashiko.dev/#/patchset/20261115180343.576773-1-koray.fra%40gmail.com?part=10 Link: https://lore.kernel.org/all/20261115180343.576773-11-koray.fra@gmail.com/ Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7 Signed-off-by: koraynilay <koray.fra@gmail.com> Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
7 daysMerge tag 'mm-core-7.4-rc4' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/mm/core Pull core memory management fixes from David Hildenbrand: "The main changes are: - Prevent folio refcount overflows with pagecache folios, mostly relevant for large folios today. The networking changes for this will go through the net tree. - Fix out-of-bounds page table accesses with folded PMDs in 3 scenarios. - Fix write-sealing of memfd to detect GUP pins with concurrent (un)mapping more reliably, preventing writes through GUP pins after write-sealing. - Fix lost wakeups when splitting large folios. - Fix exposing uninitialized data through MADV_COLLAPSE to user space. The refcount changes also include a related iommufd fix for properly cleaning up when pinning memfd folios fails, which is now easier to trigger" * tag 'mm-core-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mm/core: mm/gup: limit pagecache folio refcount when grabbing references iommufd: fix cleanup when adding memfd folio pins fails mm/mmu_gather: flush pending references early before the folio limit mm: limit pagecache folio refcount when splicing into pipes mm: limit pagecache folio refcount when mapping pages mm/huge_memory: prevent losing PG_waiters in __split_folio_to_order() mm/rmap: fix PTE table overruns during batched reference checks mm/rmap: fix PTE table overruns during batched unmap mm/userfaultfd: fix PTE table overruns in UFFDIO_MOVE mm/memfd: handle GUP pins more reliably when write-sealing mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
7 dayssmb: client: fix negative timestamps being read from smbkoraynilay
When reading a timestamp before epoch 0, cifs converts it from NT format to Unix format without normalizing it, leading to the nanoseconds field to be used as a negative number, which leads to a garbled stat command output. This bug also violates a struct timespec64 invariant, as documented in the set_normalized_timespec64() kernel-doc: [...] * Note: The tv_nsec part is always in the range of 0 <= tv_nsec < * NSEC_PER_SEC. * For negative values only the tv_sec field is negative ! */ Reproducer, with /tmp as the local filesystem folder exported as [test] in ksmbd.conf and /mnt as the smb folder mounted with mount -t cifs: mount -t cifs //127.0.0.1/test /mnt -o username=user,password=pass touch -d "1969-07-20 20:17:40.123456789" /tmp/test.txt stat -c "Server local (/tmp): %y" /tmp/test.txt stat -c "CIFS client (/mnt): %y" /mnt/test.txt --cached=never smbclient //127.0.0.1/test -U user%pass -c "allinfo test.txt" which prints (stat output is garbled because of negative value): Server local (/tmp): 1969-07-20 20:17:40.123456789 +0000 CIFS client (/mnt): 1969-07-20 20:17:41.()*+,--00 +0000 altname: TESTT~K6.TXT [...] access_time: Sun Jul 20 20:17:40 1969 UTC write_time: Sun Jul 20 20:17:40 1969 UTC [...] Fix this by using set_normalized_timespec64() in cifs_NTtimeToUnix(). Fixes: 2ae83bf93882 ("[CIFS] Fix setting time before epoch (negative time values)") Cc: stable@vger.kernel.org Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.3 Signed-off-by: koraynilay <koray.fra@gmail.com> Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
7 dayssmb: client: convert path_consumed to mount charset unitsFredric Cover
path_consumed in a DFS referral counts bytes of the canonical path, which is in the DFS cache charset (utf8). dfs_parse_target_referral() applies it as an offset into full_path, which is in the mount charset. When the mount charset is not utf8, each non-ASCII character in the consumed part that encodes longer in utf8 than in the mount charset makes the offset too large, so leading characters of the prefix path are dropped. For example, with iocharset=iso8859-1, mounting //srv/dfs/café é/sub yields the prefix "ub" instead of "sub" and the mount fails with -ENOENT. (A single accented character only worked because the offset happened to land after the delimiter.) Translate the count in parse_dfs_target(), where both strings are available, by matching path components: count the delimiters in the consumed part of the canonical path and find the same position in the mount charset path. Delimiters are ASCII in both and are not affected by remapping. If the consumed bytes are identical in both strings, which is the case for utf8 mounts and ASCII-only prefixes using the default backslash delimiter, the value is used unchanged. This assumes the server reports PathConsumed on a component boundary; a translated value that ends mid-component is rounded up to the next boundary. Tested against Samba on a KASAN kernel: with iocharset=iso8859-1, links with 0 to 3 accented characters followed by a tail, a two-level tail, an accented tail, a link in a subdirectory, and mapposix with an accented name; iso8859-15 and cp932 mounts; and iocharset=utf8 controls. Not tested against Windows servers, with posixpaths, or with reserved characters under mapchars/mapposix. Signed-off-by: Fredric Cover <fredric.cover.lkernel@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: Paulo Alcantara <pc@manguebit.org>
8 daysxfs: test for realtime and reflink under the pNFS locksChris Mason
A pNFS client can write to blocks that its file shares with another file, or that are no part of its file, if a LAYOUTGET races with a clone or with FS_IOC_FSSETXATTR. xfs_fs_map_blocks() hands out no layout for a reflinked or a realtime inode, since the client writes in place and only knows the data device. But it tests for both before it takes the IOLOCK, and both flags are set under that lock: LAYOUTGET clone ========= ===== takes the IOLOCK breaks the layouts xfs_fs_map_blocks() sees no reflink flag waits for the IOLOCK sets the reflink flag shares the blocks drops the IOLOCK maps the shared blocks /* the client writes in place */ If FS_IOC_FSSETXATTR sets the realtime flag of an empty file instead, the blocks come from the realtime device, and nfsd points the client at the same address on the data device. The fix used here is to test for both once the locks are held. Fixes: e54b5bf9d7ae ("xfs: recognize the reflink feature bit") Fixes: 527851124d10 ("xfs: implement pNFS export operations") Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: don't enable DAX on zoned inodesChris Mason
A store through a shared mapping can dereference a NULL pointer if the file is zoned and has S_DAX. The zoned code does not support DAX, but XFS doesn't check for this: with dax=always or FS_XFLAG_DAX, an inode gets S_DAX if its device does DAX, and an internal zoned section on pmem does. The write fault then takes the zoned path: xfs_filemap_fault() xfs_write_fault() xfs_write_fault_zoned() page_folio(vmf->page) /* NULL in a DAX fault */ ftruncate() crashes in a similar way, in xfs_reflink_end_cow(). The fix used here is to never set S_DAX on a zoned inode, and to refuse to change the realtime flag of an S_DAX inode on a zoned file system. Zoned files now use the page cache with dax=always or FS_XFLAG_DAX. A file whose realtime flag is cleared stays without DAX until its inode is evicted. Fixes: be458049ffe3 ("xfs: enable the zoned RT device feature") Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: restart faults racing with realtime flag changesChris Mason
On a zoned XFS, a store through a shared mapping can dereference a NULL pointer if the realtime flag of the file is set as the write fault starts. xfs_write_fault() reserves zoned space only for a zoned inode. The reservation can wait for garbage collection, which takes the MMAPLOCK, so it comes ahead of that lock, and so does the test for a zoned inode. FS_IOC_FSSETXATTR can set the flag of a file with no blocks right after the test: write fault FS_IOC_FSSETXATTR =========== ================= xfs_write_fault() sees that the inode is not zoned sets the realtime flag takes the MMAPLOCK xfs_buffered_write_iomap_begin() sees that the inode is zoned /* ac is NULL */ The fix used here is to test again under the MMAPLOCK, which keeps the ioctl out since "xfs: take the MMAPLOCK in xfs_fileattr_set()", and to start the fault over if the flag has changed. Fixes: 058dd70c65ab ("xfs: implement buffered writes to zoned RT devices") Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: take the MMAPLOCK in xfs_fileattr_set()Chris Mason
A store through a shared mapping can corrupt a realtime file system on disk, or shut a file system down, if FS_IOC_FSSETXATTR changes the realtime flag or an extent size hint of the file during the write fault. A write fault reads the flag and the hints more than once: to choose delayed allocation, to size the block reservation, and again in the allocator. All of these have to see the same values. System calls that write do the same, but they hold the IOLOCK, which keeps the ioctl out. A fault only holds the MMAPLOCK, which the ioctl does not take: write fault FS_IOC_FSSETXATTR =========== ================= takes the MMAPLOCK xfs_iomap_write_direct() reserves blocks for the old hint takes the ILOCK raises the hint drops the ILOCK takes the ILOCK xfs_bmapi_write() allocates for the new hint /* more than was reserved */ The fix used here is to make the ioctl take the MMAPLOCK of a regular file as well. Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: refuse fallocate racing with realtime flag changesChris Mason
On a zoned XFS, fallocate() can dereference a NULL pointer if the realtime flag of the file is set during the call. xfs_file_fallocate() reserves zoned space only for a zoned inode, and tests for that before it takes the iolock. FS_IOC_FSSETXATTR can change the realtime flag of a file with no blocks in that gap. xfs_falloc_force_zero() then sees a zoned inode and reads the reservation, which is NULL: fallocate(FALLOC_FL_ZERO_RANGE) FS_IOC_FSSETXATTR =============================== ================= takes the iolock sees that the inode is not zoned waits for the iolock sets the realtime flag drops the iolock xfs_falloc_force_zero() sees that the inode is zoned /* ac is NULL */ The fix used here is to test again under the iolock, and to fail the call with -EINVAL if the answer has changed, as the write path does. Fixes: 058dd70c65ab ("xfs: implement buffered writes to zoned RT devices") Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: test for always COW after the dio write checksChris Mason
A direct write to a zoned file from vectors that are not block aligned can silently corrupt the file's data, if the realtime flag is cleared and set again while the write starts. Every bio of an always COW write has to cover whole blocks, so xfs_file_dio_write_aligned() passes IOMAP_DIO_FSBLOCK_ALIGNED for such an inode. But it tests for always COW before it takes the IOLOCK, and the realtime flag of a file with no blocks can change until then: xfs_file_dio_write_zoned() FS_IOC_FSSETXATTR ========================== ================= xfs_zoned_write_space_reserve() clears the realtime flag xfs_file_dio_write_aligned() xfs_is_always_cow_inode() is false sets the realtime flag xfs_ilock_iocb_for_write() xfs_file_write_checks() iomap_dio_rw() splits a bio inside a block The fix used here is to test for always COW once the IOLOCK is held. Before commit 8caec6c9fef7 ("xfs: support sub-block aligned vectors in always COW mode"), xfs_file_dio_write() made the same test with no lock held, to send such vectors down the unaligned path. So v6.15 to v6.18 have the same race, and need a different version of this fix. Fixes: 2e2383405824 ("xfs: implement direct writes to zoned RT devices") Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: refuse writes to files racing with realtime inode flag changesChristoph Hellwig
Zoned writes need to reserve space before taking the iolock to avoid deadlocks with garbage collection. But this means that the realtime inode flag which indicates if the file will be placed on the zoned realtime device or the main data device can be flipped after taking the reservation and before taking the write, or after deciding to go down the regular write path, both of which can't work. Re-sample the realtime flag just before the actual write, and refuse the write if the flag changed. Do not retry the write using the now correct path, as switching the flag under a write is not a normal use case, and trying to flip between the zoned and regular path is an inherent life lock as it could be switched around again the next time this check is performed. Fixes: 058dd70c65ab ("xfs: implement buffered writes to zoned RT devices") Fixes: 2e2383405824 ("xfs: implement direct writes to zoned RT devices") Reported-by: Chris Mason <mason@kernel.org> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: test for reflink after the dio write checksChris Mason
A direct write that is not block aligned can expose stale disk contents on XFS if it races with the first clone of the file. xfs_file_dio_write_unaligned() falls back to buffered I/O if the file is reflinked, and tests for that right after it takes the iolock. But xfs_file_write_checks() runs after the test and can drop the iolock, for example if S_NOSEC is not set. A clone can run in that gap: direct write clone ============ ===== takes the iolock shared sees that the file is not reflinked drops the iolock shares the blocks takes the iolock exclusive writes a part of a new COW block maps the whole block into the file /* the rest was never written */ The fix used here is to move the test after xfs_file_write_checks(). Fixes: ed1128c2d0c8 ("xfs: reduce exclusive locking on unaligned dio") Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: properly order xfsstats proc/sysfs init and teardownEric Sandeen
The xfs statistics are accessible both through procfs and through sysctls, so they need to be fully set up before exposure via those interfaces, and those interfaces both need to be torn down before the underlying percpu structures are freed. Today we get that wrong on both ends - we expose them through xfs_init_procfs before allocating the percpu structures, and we free those percpu structures before tearing down sysctls and procfs. Fix init_xfs_fs by calling alloc_percpu(xfsstats) prior to xfs_init_procfs(), and fix the error unwind path to reflect this, then also move free_percpu() to after tearing down both procfs and sysctls in exit_xfs_fs. Reported-by: Hanxiang Xu <xuhx@hust.edu.cn> Fixes: 80529c45ab66 ("xfs: pass xfsstats structures to handlers and macros") Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: remove unused variable in xrep_tempfile_copyin()Yiqing Wu
The pos variable in xrep_tempfile_copyin() is initialized from the starting file offset and incremented on every iteration of the copy loop, but it is never used. GCC flags this as a dead assignment when building with W=1: fs/xfs/scrub/tempfile.c:493:33: warning: variable pos set but not used [-Wunused-but-set-variable=] Drop the variable and the loop increment. Signed-off-by: Yiqing Wu <wuyiqing@cmss.chinamobile.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: remove unused variable in xchk_stats_estimate_bufsize()Yiqing Wu
The css variable in xchk_stats_estimate_bufsize() is initialized to point to the start of the cs_stats array and incremented on every iteration of the scan loop, but it is never dereferenced. GCC flags this as a dead assignment when building with W=1: fs/xfs/scrub/stats.c:146:34: warning: variable css set but not used [-Wunused-but-set-variable=] Drop the variable and the loop increment. Signed-off-by: Yiqing Wu <wuyiqing@cmss.chinamobile.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: fix f_bfree underflow in statfs()Hengyu Liang
Commit dd324cb79e54 ("xfs: refactor xfs_fs_statfs") made xfs_statfs_data() limit f_bfree with max(0LL, ...) instead of max_t(int64_t, 0, ...). However, the value is an unsigned difference, so max() never picks 0. As of now, when the free block counter is below the count of unavailable blocks, statfs() reports f_bfree and f_bavail close to 2^64 instead of 0, and df prints negative sizes. A similar issue happened before and was fixed by commit 237aac4624aa ("xfs: ensure f_bfree returned by statfs() is non-negative"). Perhaps the refactored code needs that fix as well. The issue can be reproduced on a new 2 GiB filesystem mounted on /mnt: for i in $(seq 3000); do head -c 65536 /dev/zero > /mnt/s$i; done dd if=/dev/zero of=/mnt/big bs=1M xfs_io -x -c 'resblks 100000000' /mnt for i in $(seq 1 2 3000); do rm /mnt/s$i; done sync df -h /mnt Before commit dd324cb79e54 ("xfs: refactor xfs_fs_statfs"), the result is: Filesystem Size Used Avail Use% Mounted on /dev/vda 2.0G 2.0G 0 100% /mnt After that commit, the result is: Filesystem Size Used Avail Use% Mounted on /dev/vda 2.0G -64Z -24K 100% /mnt This patch will compare the difference as a signed value again. Fixes: dd324cb79e54 ("xfs: refactor xfs_fs_statfs") Cc: stable@vger.kernel.org # v6.14 Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 daysxfs: wait for direct I/O before swapping extentsDaejun Park
An AIO direct write drops the iolock before its bios complete. XFS_IOC_SWAPEXT does not wait for it. The write can land in blocks that the swap moved to the temporary file. Once xfs_fsr frees them, the write corrupts whatever reuses them. Wait for direct I/O first, as exchange-range does. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Daejun Park <daejun7.park@samsung.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>