linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Baokun Li <libaokun1@huawei.com>
To: <richard@nod.at>, <linux-mtd@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: <libaokun1@huawei.com>, <yukuai3@huawei.com>,
	Hulk Robot <hulkci@huawei.com>
Subject: [PATCH -next 2/3] ubifs: fix double return leb in ubifs_garbage_collect
Date: Mon, 15 Nov 2021 09:31:43 +0800	[thread overview]
Message-ID: <20211115013144.2479319-3-libaokun1@huawei.com> (raw)
In-Reply-To: <20211115013144.2479319-1-libaokun1@huawei.com>

If ubifs_garbage_collect_leb() returns -EAGAIN and enters the "out"
branch, ubifs_return_leb will execute twice on the same lnum. This
can cause data loss in concurrency situations.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
 fs/ubifs/gc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 05e1eeae8457..1f74a127fe3a 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -758,6 +758,8 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway)
 				err = ubifs_return_leb(c, lp.lnum);
 				if (err)
 					ret = err;
+				/*  Maybe double return LEB if goto out */
+				lp.lnum = -1;
 				break;
 			}
 			goto out;
-- 
2.31.1


  parent reply	other threads:[~2021-11-15  1:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15  1:31 [PATCH -next 0/3] fix some bugs in ubifs_garbage_collect Baokun Li
2021-11-15  1:31 ` [PATCH -next 1/3] ubifs: fix slab-out-of-bounds in ubifs_change_lp Baokun Li
2021-11-15  1:31 ` Baokun Li [this message]
2021-11-15  1:31 ` [PATCH -next 3/3] ubifs: read-only if LEB may always be taken in ubifs_garbage_collect Baokun Li
2021-12-21 12:35 ` [PATCH -next 0/3] fix some bugs " libaokun (A)

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=20211115013144.2479319-3-libaokun1@huawei.com \
    --to=libaokun1@huawei.com \
    --cc=hulkci@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=yukuai3@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).