Message ID | 20221025082835.3751-1-zeming@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp886985wru; Tue, 25 Oct 2022 01:56:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6cP801L/6N/Ll4fJvNoG5HmrOWn0AUSlG1TlgpQli8SA6Mct2nc9niYmfUMrP8l7F02GoG X-Received: by 2002:a17:903:2450:b0:185:4165:be54 with SMTP id l16-20020a170903245000b001854165be54mr37787544pls.104.1666688185178; Tue, 25 Oct 2022 01:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666688185; cv=none; d=google.com; s=arc-20160816; b=PoFsYGRPK8ULYdp+xS404golO4Yebl6CMMIeeRUmeRwYlzLXv66tnMTTe1E8HDolEk O6NPlF7q4j3e/JFVI3C2LXZK9tWkWJh9EvCZa7emks83/Cj2EZLQIbC04qvXZ7VbrnlT 5pohmBxLsRLfLiJfjUtGD2TSqz4kfYqXc1InvUoOlcmWjjzy0bzPWEJ23FZn/DqrWWpi 2Mc8P5+ND9f6lVDuCH9HtAqebmO5n7XeC6Nm+V0HO5cIdIrbZ5XxjrePcZBxqifWCn49 D3Ab0l3FVJPdePF/6KpoAVVbaHcZ9X1/Uf9M3rRbKTpM+2FhIlgL2wRSZ6D2YeVkRiM8 rVwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=y67YZPae/MMAdDbSEoySCBhLfdwjFar8ncOEUvBtCTA=; b=sZA1fgVyIacFu/0OoEgjO4FN2k0Ht4nE4rzNb6x4x8SWKIY5JEf4v5o8pUSfbLXcqb vfXMWXcefL76WxjRLKVPY6mOxfTku/QHnFSjI55Uc9vsVsmx/miUPJ7IykpAfVH6BePO O5xnwzbBJZWmpgKQFKVS/+OlaBInl1jBubJEC1vUuAFZEfVoQDOAw8taI/DVqiJzKrE3 uvj4piBWFO3eHHddfrWz64xpz8omDuk7vURJj5S9F7ompDevKptoDKmt6UH2mcELR3TN iIQAtvbtYeu8cNpZ/ZOE4roK/BdEeKoqed7Rb9ckLYzLa/BIX0MfkpWqIRk49p3uMl9+ wdlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a170902f2cb00b0017f9b980fadsi1770005plc.446.2022.10.25.01.56.11; Tue, 25 Oct 2022 01:56:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbiJYI2o (ORCPT <rfc822;lucius.rs.storz@gmail.com> + 99 others); Tue, 25 Oct 2022 04:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232199AbiJYI2m (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Oct 2022 04:28:42 -0400 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43EDAE984F; Tue, 25 Oct 2022 01:28:41 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id BA2AB1E80C8E; Tue, 25 Oct 2022 16:27:18 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Uuw8E96Tt7r7; Tue, 25 Oct 2022 16:27:16 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 300B21E80C82; Tue, 25 Oct 2022 16:27:16 +0800 (CST) From: Li zeming <zeming@nfschina.com> To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Li zeming <zeming@nfschina.com> Subject: [PATCH] btrfs: volumes: Increase bioc pointer check Date: Tue, 25 Oct 2022 16:28:35 +0800 Message-Id: <20221025082835.3751-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747649230174388512?= X-GMAIL-MSGID: =?utf-8?q?1747649230174388512?= |
Series |
btrfs: volumes: Increase bioc pointer check
|
|
Commit Message
Li zeming
Oct. 25, 2022, 8:28 a.m. UTC
If kzalloc fails to allocate the bioc pointer, NULL is returned
directly.
Signed-off-by: Li zeming <zeming@nfschina.com>
---
fs/btrfs/volumes.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On 25.10.22 г. 11:28 ч., Li zeming wrote: > If kzalloc fails to allocate the bioc pointer, NULL is returned > directly. > > Signed-off-by: Li zeming <zeming@nfschina.com> This patch clearly shows you haven't really understood the code. As is evident there is __GFP_NOFAIL flag so as per the guarantees for this flag we either loop infinitely trying to allocate a bioc or simply allocated it. So this check can never be triggered. NAK > --- > fs/btrfs/volumes.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 064ab2a79c80..f9cb815fe23d 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -5892,6 +5892,8 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ > */ > sizeof(u64) * (total_stripes), > GFP_NOFS|__GFP_NOFAIL); > + if (!bioc) > + return NULL; > > atomic_set(&bioc->error, 0); > refcount_set(&bioc->refs, 1);
On 2022/10/25 16:28, Li zeming wrote: > If kzalloc fails to allocate the bioc pointer, NULL is returned > directly. s/is returned/should be returned/ > > Signed-off-by: Li zeming <zeming@nfschina.com> > --- > fs/btrfs/volumes.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 064ab2a79c80..f9cb815fe23d 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -5892,6 +5892,8 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ > */ > sizeof(u64) * (total_stripes), > GFP_NOFS|__GFP_NOFAIL); I think you can also remove the __GFP_NOFAIL flag. Especially the only caller is properly handling the error. With that __GFP_NOFAIL flag there, it should not fail, but we can not just rely on NOFAIL flag to save our asses. Otherwise looks good to me. With above two points fixed, you can add my tag: Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > + if (!bioc) > + return NULL; > > atomic_set(&bioc->error, 0); > refcount_set(&bioc->refs, 1);
On 2022/10/25 17:29, Nikolay Borisov wrote: > > > On 25.10.22 г. 11:28 ч., Li zeming wrote: >> If kzalloc fails to allocate the bioc pointer, NULL is returned >> directly. >> >> Signed-off-by: Li zeming <zeming@nfschina.com> > > This patch clearly shows you haven't really understood the code. As is > evident there is __GFP_NOFAIL flag so as per the guarantees for this > flag we either loop infinitely trying to allocate a bioc or simply > allocated it. So this check can never be triggered. I guess what he missed is just to also remove that NOFAIL flag. NOFAIL will not 100% guarantee the allocation, and I don't see this location to be so important, especially when the only caller is already handing allocation failure. Thanks, Qu > > NAK >> --- >> fs/btrfs/volumes.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c >> index 064ab2a79c80..f9cb815fe23d 100644 >> --- a/fs/btrfs/volumes.c >> +++ b/fs/btrfs/volumes.c >> @@ -5892,6 +5892,8 @@ static struct btrfs_io_context >> *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ >> */ >> sizeof(u64) * (total_stripes), >> GFP_NOFS|__GFP_NOFAIL); >> + if (!bioc) >> + return NULL; >> atomic_set(&bioc->error, 0); >> refcount_set(&bioc->refs, 1);
very thankful. I have fixed these two problems and am ready to release v2 patches.
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 064ab2a79c80..f9cb815fe23d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5892,6 +5892,8 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ */ sizeof(u64) * (total_stripes), GFP_NOFS|__GFP_NOFAIL); + if (!bioc) + return NULL; atomic_set(&bioc->error, 0); refcount_set(&bioc->refs, 1);