linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubifs: Fix wrong orphan node deletion in ubifs_jnl_update()
@ 2020-07-02 15:20 Zhihao Cheng
  2020-07-07 11:52 ` Richard Weinberger
  0 siblings, 1 reply; 3+ messages in thread
From: Zhihao Cheng @ 2020-07-02 15:20 UTC (permalink / raw)
  To: linux-mtd, linux-kernel; +Cc: richard, yi.zhang

There a wrong orphan node deleting in error handling path in
ubifs_jnl_update(), which may cause following error msg:

  UBIFS error (ubi0:0 pid 1522): ubifs_delete_orphan [ubifs]:
  missing orphan ino 65

Fix this by checking whether the node has been operated for
adding to orphan list before being deleted,

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
 fs/ubifs/journal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index e5ec1afe1c66..db0a80dd9d52 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
 		     const struct fscrypt_name *nm, const struct inode *inode,
 		     int deletion, int xent)
 {
-	int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
+	int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
 	int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
 	int last_reference = !!(deletion && inode->i_nlink == 0);
 	struct ubifs_inode *ui = ubifs_inode(inode);
@@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
 			goto out_finish;
 		}
 		ui->del_cmtno = c->cmt_no;
+		orphan_added = 1;
 	}
 
 	err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync);
@@ -702,7 +703,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
 	kfree(dent);
 out_ro:
 	ubifs_ro_mode(c, err);
-	if (last_reference)
+	if (last_reference && orphan_added)
 		ubifs_delete_orphan(c, inode->i_ino);
 	finish_reservation(c);
 	return err;
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ubifs: Fix wrong orphan node deletion in ubifs_jnl_update()
  2020-07-02 15:20 [PATCH] ubifs: Fix wrong orphan node deletion in ubifs_jnl_update() Zhihao Cheng
@ 2020-07-07 11:52 ` Richard Weinberger
  2020-07-07 11:57   ` Zhihao Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Weinberger @ 2020-07-07 11:52 UTC (permalink / raw)
  To: Zhihao Cheng; +Cc: linux-mtd, LKML, Richard Weinberger, zhangyi (F)

On Thu, Jul 2, 2020 at 5:21 PM Zhihao Cheng <chengzhihao1@huawei.com> wrote:
>
> There a wrong orphan node deleting in error handling path in
> ubifs_jnl_update(), which may cause following error msg:
>
>   UBIFS error (ubi0:0 pid 1522): ubifs_delete_orphan [ubifs]:
>   missing orphan ino 65
>
> Fix this by checking whether the node has been operated for
> adding to orphan list before being deleted,
>
> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
> ---
>  fs/ubifs/journal.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
> index e5ec1afe1c66..db0a80dd9d52 100644
> --- a/fs/ubifs/journal.c
> +++ b/fs/ubifs/journal.c
> @@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>                      const struct fscrypt_name *nm, const struct inode *inode,
>                      int deletion, int xent)
>  {
> -       int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
> +       int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
>         int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
>         int last_reference = !!(deletion && inode->i_nlink == 0);
>         struct ubifs_inode *ui = ubifs_inode(inode);
> @@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>                         goto out_finish;
>                 }
>                 ui->del_cmtno = c->cmt_no;
> +               orphan_added = 1;
>         }
>
>         err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync);
> @@ -702,7 +703,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>         kfree(dent);
>  out_ro:
>         ubifs_ro_mode(c, err);
> -       if (last_reference)
> +       if (last_reference && orphan_added)

I think you can just check for orphan_added here.
Looks good otherwise, thanks for fixing! :-)

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ubifs: Fix wrong orphan node deletion in ubifs_jnl_update()
  2020-07-07 11:52 ` Richard Weinberger
@ 2020-07-07 11:57   ` Zhihao Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Zhihao Cheng @ 2020-07-07 11:57 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: linux-mtd, LKML, Richard Weinberger, zhangyi (F)

在 2020/7/7 19:52, Richard Weinberger 写道:
> On Thu, Jul 2, 2020 at 5:21 PM Zhihao Cheng <chengzhihao1@huawei.com> wrote:
>> There a wrong orphan node deleting in error handling path in
>> ubifs_jnl_update(), which may cause following error msg:
>>
>>    UBIFS error (ubi0:0 pid 1522): ubifs_delete_orphan [ubifs]:
>>    missing orphan ino 65
>>
>> Fix this by checking whether the node has been operated for
>> adding to orphan list before being deleted,
>>
>> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
>> ---
>>   fs/ubifs/journal.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
>> index e5ec1afe1c66..db0a80dd9d52 100644
>> --- a/fs/ubifs/journal.c
>> +++ b/fs/ubifs/journal.c
>> @@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>>                       const struct fscrypt_name *nm, const struct inode *inode,
>>                       int deletion, int xent)
>>   {
>> -       int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
>> +       int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
>>          int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
>>          int last_reference = !!(deletion && inode->i_nlink == 0);
>>          struct ubifs_inode *ui = ubifs_inode(inode);
>> @@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>>                          goto out_finish;
>>                  }
>>                  ui->del_cmtno = c->cmt_no;
>> +               orphan_added = 1;
>>          }
>>
>>          err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync);
>> @@ -702,7 +703,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>>          kfree(dent);
>>   out_ro:
>>          ubifs_ro_mode(c, err);
>> -       if (last_reference)
>> +       if (last_reference && orphan_added)
> I think you can just check for orphan_added here.
> Looks good otherwise, thanks for fixing! :-)
Sounds reasonable. I will send v2.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-07 11:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 15:20 [PATCH] ubifs: Fix wrong orphan node deletion in ubifs_jnl_update() Zhihao Cheng
2020-07-07 11:52 ` Richard Weinberger
2020-07-07 11:57   ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).