* [PATCH] fs/btrfs: init csum_list before possible free
@ 2019-02-19 2:56 Dan Robertson
2019-02-19 5:45 ` Nikolay Borisov
2019-02-19 16:31 ` David Sterba
0 siblings, 2 replies; 6+ messages in thread
From: Dan Robertson @ 2019-02-19 2:56 UTC (permalink / raw)
To: linux-btrfs; +Cc: Dan Robertson
The scrub_ctx csum_list member must be initialized before
scrub_free_ctx is called. If the csum_list is not initialized
beforehand, the list_empty call in scrub_free_csums will result
in a null deref.
Signed-off-by: Dan Robertson <dan@dlrobertson.com>
---
fs/btrfs/scrub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 6dcd36d7b849..1e08ad1fe2aa 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -584,6 +584,7 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx(
sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
sctx->curr = -1;
sctx->fs_info = fs_info;
+ INIT_LIST_HEAD(&sctx->csum_list);
for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
struct scrub_bio *sbio;
@@ -608,7 +609,6 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx(
atomic_set(&sctx->workers_pending, 0);
atomic_set(&sctx->cancel_req, 0);
sctx->csum_size = btrfs_super_csum_size(fs_info->super_copy);
- INIT_LIST_HEAD(&sctx->csum_list);
spin_lock_init(&sctx->list_lock);
spin_lock_init(&sctx->stat_lock);
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: init csum_list before possible free
2019-02-19 2:56 [PATCH] fs/btrfs: init csum_list before possible free Dan Robertson
@ 2019-02-19 5:45 ` Nikolay Borisov
2019-02-19 16:31 ` David Sterba
1 sibling, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2019-02-19 5:45 UTC (permalink / raw)
To: Dan Robertson, linux-btrfs
On 19.02.19 г. 4:56 ч., Dan Robertson wrote:
> The scrub_ctx csum_list member must be initialized before
> scrub_free_ctx is called. If the csum_list is not initialized
> beforehand, the list_empty call in scrub_free_csums will result
> in a null deref.
>
> Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/scrub.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 6dcd36d7b849..1e08ad1fe2aa 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -584,6 +584,7 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx(
> sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
> sctx->curr = -1;
> sctx->fs_info = fs_info;
> + INIT_LIST_HEAD(&sctx->csum_list);
> for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
> struct scrub_bio *sbio;
>
> @@ -608,7 +609,6 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx(
> atomic_set(&sctx->workers_pending, 0);
> atomic_set(&sctx->cancel_req, 0);
> sctx->csum_size = btrfs_super_csum_size(fs_info->super_copy);
> - INIT_LIST_HEAD(&sctx->csum_list);
>
> spin_lock_init(&sctx->list_lock);
> spin_lock_init(&sctx->stat_lock);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: init csum_list before possible free
2019-02-19 2:56 [PATCH] fs/btrfs: init csum_list before possible free Dan Robertson
2019-02-19 5:45 ` Nikolay Borisov
@ 2019-02-19 16:31 ` David Sterba
2019-02-21 14:57 ` Dan Robertson
1 sibling, 1 reply; 6+ messages in thread
From: David Sterba @ 2019-02-19 16:31 UTC (permalink / raw)
To: Dan Robertson; +Cc: linux-btrfs
On Tue, Feb 19, 2019 at 02:56:43AM +0000, Dan Robertson wrote:
> The scrub_ctx csum_list member must be initialized before
> scrub_free_ctx is called. If the csum_list is not initialized
> beforehand, the list_empty call in scrub_free_csums will result
> in a null deref.
>
> Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Thanks, it's been there since the first merge of scrub, but hard to hit.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: init csum_list before possible free
2019-02-19 16:31 ` David Sterba
@ 2019-02-21 14:57 ` Dan Robertson
2019-02-22 15:57 ` David Sterba
0 siblings, 1 reply; 6+ messages in thread
From: Dan Robertson @ 2019-02-21 14:57 UTC (permalink / raw)
To: dsterba, linux-btrfs
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
> Thanks, it's been there since the first merge of scrub, but hard to hit.
Yeah, very hard to hit. Debated submitting a patch, but the fix seemed
simple enough, so figured I'd send one in.
Side note: I noticed most of the time ENOMEM is hit in fs/btrfs BUG or BUG_ON is
called. Would it be better (more in line with the fs/btrfs style) to call BUG or
BUG_ON e.g. BUG_ON(!sbio) instead of goto nomem at fs/btrfs/scrub.c:592?
Cheers,
Dan
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: init csum_list before possible free
2019-02-21 14:57 ` Dan Robertson
@ 2019-02-22 15:57 ` David Sterba
2019-02-22 16:45 ` Dan Robertson
0 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2019-02-22 15:57 UTC (permalink / raw)
To: Dan Robertson; +Cc: dsterba, linux-btrfs
On Thu, Feb 21, 2019 at 02:57:27PM +0000, Dan Robertson wrote:
> > Thanks, it's been there since the first merge of scrub, but hard to hit.
>
> Yeah, very hard to hit. Debated submitting a patch, but the fix seemed
> simple enough, so figured I'd send one in.
>
> Side note: I noticed most of the time ENOMEM is hit in fs/btrfs BUG or BUG_ON is
> called. Would it be better (more in line with the fs/btrfs style) to call BUG or
> BUG_ON e.g. BUG_ON(!sbio) instead of goto nomem at fs/btrfs/scrub.c:592?
No, we want to get rid of the BUG_ONs as a poor substitute for error
handling. The ENOMEM case is usually a hard one to fix so you still can
see a lot of them, but there are places where it's simple enough to
rollback and return ENOMEM up to the original caller. Scrub in this case
is restartable and if scrub_setup_ctx fails, it's at the time of start
and the user is properly notified.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: init csum_list before possible free
2019-02-22 15:57 ` David Sterba
@ 2019-02-22 16:45 ` Dan Robertson
0 siblings, 0 replies; 6+ messages in thread
From: Dan Robertson @ 2019-02-22 16:45 UTC (permalink / raw)
To: dsterba, linux-btrfs
[-- Attachment #1: Type: text/plain, Size: 38 bytes --]
Got it. Thanks for the clarification.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-02-22 16:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-19 2:56 [PATCH] fs/btrfs: init csum_list before possible free Dan Robertson
2019-02-19 5:45 ` Nikolay Borisov
2019-02-19 16:31 ` David Sterba
2019-02-21 14:57 ` Dan Robertson
2019-02-22 15:57 ` David Sterba
2019-02-22 16:45 ` Dan Robertson
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).