]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/ksmbd-retrieve-number-of-blocks-using-vfs_getattr-in.patch
6.6-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.15 / ksmbd-retrieve-number-of-blocks-using-vfs_getattr-in.patch
1 From 1d0bbb6737df1beed9e9834bc26e6b577579f872 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Thu, 22 Feb 2024 10:58:21 +0100
4 Subject: ksmbd: retrieve number of blocks using vfs_getattr in
5 set_file_allocation_info
6
7 From: Marios Makassikis <mmakassikis@freebox.fr>
8
9 [ Upstream commit 34cd86b6632718b7df3999d96f51e63de41c5e4f ]
10
11 Use vfs_getattr() to retrieve stat information, rather than make
12 assumptions about how a filesystem fills inode structs.
13
14 Cc: stable@vger.kernel.org
15 Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
16 Acked-by: Namjae Jeon <linkinjeon@kernel.org>
17 Signed-off-by: Steve French <stfrench@microsoft.com>
18 Signed-off-by: Sasha Levin <sashal@kernel.org>
19 ---
20 fs/ksmbd/smb2pdu.c | 10 ++++++++--
21 1 file changed, 8 insertions(+), 2 deletions(-)
22
23 diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
24 index 0613b8d14409c..14cd86a14012f 100644
25 --- a/fs/ksmbd/smb2pdu.c
26 +++ b/fs/ksmbd/smb2pdu.c
27 @@ -5759,15 +5759,21 @@ static int set_file_allocation_info(struct ksmbd_work *work,
28
29 loff_t alloc_blks;
30 struct inode *inode;
31 + struct kstat stat;
32 int rc;
33
34 if (!(fp->daccess & FILE_WRITE_DATA_LE))
35 return -EACCES;
36
37 + rc = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS,
38 + AT_STATX_SYNC_AS_STAT);
39 + if (rc)
40 + return rc;
41 +
42 alloc_blks = (le64_to_cpu(file_alloc_info->AllocationSize) + 511) >> 9;
43 inode = file_inode(fp->filp);
44
45 - if (alloc_blks > inode->i_blocks) {
46 + if (alloc_blks > stat.blocks) {
47 smb_break_all_levII_oplock(work, fp, 1);
48 rc = vfs_fallocate(fp->filp, FALLOC_FL_KEEP_SIZE, 0,
49 alloc_blks * 512);
50 @@ -5775,7 +5781,7 @@ static int set_file_allocation_info(struct ksmbd_work *work,
51 pr_err("vfs_fallocate is failed : %d\n", rc);
52 return rc;
53 }
54 - } else if (alloc_blks < inode->i_blocks) {
55 + } else if (alloc_blks < stat.blocks) {
56 loff_t size;
57
58 /*
59 --
60 2.43.0
61