Commit a02720a9 authored by Amir Goldstein's avatar Amir Goldstein Committed by Baokun Li
Browse files

fs: create kiocb_{start,end}_write() helpers

stable inclusion
from stable-v5.10.230
commit f83a32351efd6c6676fdabd5ab0e680500bc48e0
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IB5KQC
CVE: CVE-2024-53052

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f83a32351efd6c6676fdabd5ab0e680500bc48e0



--------------------------------

Commit ed0360bb upstream.

aio, io_uring, cachefiles and overlayfs, all open code an ugly variant
of file_{start,end}_write() to silence lockdep warnings.

Create helpers for this lockdep dance so we can use the helpers in all
the callers.

Suggested-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarJens Axboe <axboe@kernel.dk>
Message-Id: <20230817141337.1025891-4-amir73il@gmail.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
parent 92611cf6
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -1815,6 +1815,41 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb)
	return __sb_start_write_trylock(sb, SB_FREEZE_FS);
}

/**
 * kiocb_start_write - get write access to a superblock for async file io
 * @iocb: the io context we want to submit the write with
 *
 * This is a variant of sb_start_write() for async io submission.
 * Should be matched with a call to kiocb_end_write().
 */
static inline void kiocb_start_write(struct kiocb *iocb)
{
	struct inode *inode = file_inode(iocb->ki_filp);

	sb_start_write(inode->i_sb);
	/*
	 * Fool lockdep by telling it the lock got released so that it
	 * doesn't complain about the held lock when we return to userspace.
	 */
	__sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);
}

/**
 * kiocb_end_write - drop write access to a superblock after async file io
 * @iocb: the io context we sumbitted the write with
 *
 * Should be matched with a call to kiocb_start_write().
 */
static inline void kiocb_end_write(struct kiocb *iocb)
{
	struct inode *inode = file_inode(iocb->ki_filp);

	/*
	 * Tell lockdep we inherited freeze protection from submission thread.
	 */
	__sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE);
	sb_end_write(inode->i_sb);
}

extern bool inode_owner_or_capable(const struct inode *inode);