All of lore.kernel.org
 help / color / mirror / Atom feed
From: Murphy Zhou <jencce.kernel@gmail.com>
To: linux-cifs@vger.kernel.org
Cc: Ronnie Sahlberg <lsahlber@redhat.com>, Steve French <sfrench@samba.org>
Subject: [PATCH] CIFS: check new file size when extending file by fallocate
Date: Wed, 18 Mar 2020 09:56:24 +0800	[thread overview]
Message-ID: <20200318015624.spmlc7izbszkpdqf@xzhoux.usersys.redhat.com> (raw)

xfstests generic/228 checks if fallocate respects RLIMIT_FSIZE.
After fallocate mode 0 extending enabled, cifs can hit this failure.
Fix this by checking the new file size with the vfs helper, which
checks with RLIMIT_FSIZE(ulimit -f) and s_maxbytes.

This patch has been tested by LTP/xfstests aginst samba and
Windows server. No new issue was found.

Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
---
 fs/cifs/smb2ops.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index c31e84ee3c39..48bbbb68540d 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3246,10 +3246,14 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
 	 * Extending the file
 	 */
 	if ((keep_size == false) && i_size_read(inode) < off + len) {
+		eof = cpu_to_le64(off + len);
+		rc = inode_newsize_ok(inode, eof);
+		if (rc)
+			goto out;
+
 		if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
 			smb2_set_sparse(xid, tcon, cfile, inode, false);
 
-		eof = cpu_to_le64(off + len);
 		rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
 				  cfile->fid.volatile_fid, cfile->pid, &eof);
 		if (rc == 0) {
-- 
2.20.1

             reply	other threads:[~2020-03-18  1:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18  1:56 Murphy Zhou [this message]
2020-03-18  2:01 ` [PATCH] CIFS: check new file size when extending file by fallocate ronnie sahlberg
2020-03-18  5:57 ` Steve French
2020-03-18 11:27   ` Murphy Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200318015624.spmlc7izbszkpdqf@xzhoux.usersys.redhat.com \
    --to=jencce.kernel@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    --cc=sfrench@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.