mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Hungyu Lin <dennylin0707@gmail.com>, <richard@nod.at>
Cc: <lin.nan@h3c.com>, <linux-mtd@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH] ubifs: account for short copies in ubifs_write_end
Date: Thu, 5 Nov 2026 11:38:49 +0800	[thread overview]
Message-ID: <fb5c1cc4-d974-73ae-3b61-c0dc1363305a@huawei.com> (raw)
In-Reply-To: <20261104191132.89515-1-dennylin0707@gmail.com>

在 2026/11/5 3:11, Hungyu Lin 写道:
> ubifs_write_end() updates i_size and ui_size to pos + len even when
> fewer bytes were copied. A one-byte write at EOF from an unreadable
> buffer can fail with EFAULT while extending the file by one byte.
> Partial writes can also extend the file past the last byte copied.
> 
> Use pos + copied for size updates and cancel the budget when no data
> was copied. Keep the appending decision based on the requested length
> to match the inode budgeting and ui_mutex locking in ubifs_write_begin().
> If a short copy ends within the old size, release any unused inode budget
> without reducing the size, and still unlock ui_mutex.
> 
> Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
> Link: https://lore.kernel.org/linux-mtd/20261027061226.3506517-1-lin.nan@h3c.com/
> Cc: stable@vger.kernel.org
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
>   fs/ubifs/file.c | 29 +++++++++++++++++++----------
>   1 file changed, 19 insertions(+), 10 deletions(-)
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> 
> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index 99dd52715ee..8ebd3f4cddf 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -523,8 +523,8 @@ static int ubifs_write_end(const struct kiocb *iocb,
>   	struct inode *inode = mapping->host;
>   	struct ubifs_inode *ui = ubifs_inode(inode);
>   	struct ubifs_info *c = inode->i_sb->s_fs_info;
> -	loff_t end_pos = pos + len;
> -	int appending = !!(end_pos > inode->i_size);
> +	loff_t end_pos = pos + copied;
> +	int appending = !!(pos + len > inode->i_size);
>   
>   	dbg_gen("ino %llu, pos %llu, pg %lu, len %u, copied %d, i_size %lld",
>   		inode->i_ino, pos, folio->index, len, copied, inode->i_size);
> @@ -552,6 +552,11 @@ static int ubifs_write_end(const struct kiocb *iocb,
>   		goto out;
>   	}
>   
> +	if (unlikely(!copied)) {
> +		cancel_budget(c, folio, ui, appending);
> +		goto out;
> +	}
> +
>   	if (len == folio_size(folio))
>   		folio_mark_uptodate(folio);
>   
> @@ -562,14 +567,18 @@ static int ubifs_write_end(const struct kiocb *iocb,
>   	}
>   
>   	if (appending) {
> -		i_size_write(inode, end_pos);
> -		ui->ui_size = end_pos;
> -		/*
> -		 * We do not set @I_DIRTY_PAGES (which means that
> -		 * the inode has dirty pages), this was done in
> -		 * filemap_dirty_folio().
> -		 */
> -		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
> +		if (end_pos > inode->i_size) {
> +			i_size_write(inode, end_pos);
> +			ui->ui_size = end_pos;
> +			/*
> +			 * We do not set @I_DIRTY_PAGES (which means that
> +			 * the inode has dirty pages), this was done in
> +			 * filemap_dirty_folio().
> +			 */
> +			__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
> +		} else if (!ui->dirty) {
> +			ubifs_release_dirty_inode_budget(c, ui);
> +		}
>   		ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
>   		mutex_unlock(&ui->ui_mutex);
>   	}
> 
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> 


      reply	other threads:[~2026-11-05  3:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 19:11 Hungyu Lin
2026-11-05  3:38 ` Zhihao Cheng [this message]

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=fb5c1cc4-d974-73ae-3b61-c0dc1363305a@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=dennylin0707@gmail.com \
    --cc=lin.nan@h3c.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®