Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1150114rwi; Thu, 3 Nov 2022 01:31:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM74mxADRHLJS/CZN1TOp1dIoFkHPUAT7/Rnd1IKQPVDuvctMsle1HpFr8Y0TKUZwRHcvXce X-Received: by 2002:a17:906:e83:b0:7ae:c0c:210b with SMTP id p3-20020a1709060e8300b007ae0c0c210bmr5553266ejf.523.1667464287534; Thu, 03 Nov 2022 01:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667464287; cv=none; d=google.com; s=arc-20160816; b=w5JOQZUc0508tGH039/337Q7Q3i3BOJGz/u9UCUqQkeQjyGeOXYLv3yxyTC30dFnsK SbPUpOYpDi8EnjMDJk9dNBoVedeO8YJUk0gmomA0NICj+hnqp4aHjEke0+jUAVB1JU1n f+bWcL5xf3RYbeViC2TOS2YqSTVpyeHA1JoPKBFBXTAaBKGo5F0nVLGnCLvIVYy0IRUS Z1ALz/PwUx9WLsHrVKBGyDzeyQHBt97pgYuQQd5LfkS5t7s6COdw4fIwIRqGHNRHXhVo ZZZnzuyafwbRW8rIMe9Su7Wt6AWV2cQoBHnHxZJu907ugYJOyQ2rJ1MRgk38wdvpDdoK kX9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ouZNBMNvvrnkZSRBeuTvoKMw9UcQXO1wNpACVbg3cbo=; b=x30Cfk/SlsUvD/K9+ixXqymMpnomUR9Is8wk/PYHJ0himu0UsRaQ0st9Tj/sa1gkRE 1DvEVcqHnt9INxBq1GO3Co3/SIFJ0XgfhQ4YMmeFiA/T3yzomNIH6LM/bRX4iopXGJhO RzkXUojoYcgOgZEN/zP8y7Ze0NHhQoaDp5mEMvRds1AsB9gMDbEo5fNyPmJ0mzK3nvTU kkftGI9R66cd+yYAuYxfq2EPqIJ+zpC3DK66EcZfkM0R2qswLWNLLrJ1I8cUa2lBwcn6 7g8II8vP3pPT7FJ/67uVocUDguPsz5EC0elJCAJ3Fpi/WIAo6IqSqNIMvCEr5bpP4/2N 8hzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FHIiUHpq; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a056402321600b00459c1e64776si450790eda.412.2022.11.03.01.31.03; Thu, 03 Nov 2022 01:31:27 -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; dkim=pass header.i=@suse.com header.s=susede1 header.b=FHIiUHpq; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231165AbiKCIUn (ORCPT + 97 others); Thu, 3 Nov 2022 04:20:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbiKCIUg (ORCPT ); Thu, 3 Nov 2022 04:20:36 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB8786401; Thu, 3 Nov 2022 01:20:34 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7B603220CC; Thu, 3 Nov 2022 08:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667463633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ouZNBMNvvrnkZSRBeuTvoKMw9UcQXO1wNpACVbg3cbo=; b=FHIiUHpq8kqmiBvbiZIzQZcHVVijmK/UpBmXYgGDDpKMjhoes0eoyBDNsIOT+feaqkxFxg YaUrdak8yGX8ckWchrmP7gtE+g+RW3hVqzIizF+UtLlNdv0/3dRac3hSUr2TMFwMX+wv1A EpaQKNqflIpCrvhc/yLew8VCMAP9ZTE= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 25B3C13AAF; Thu, 3 Nov 2022 08:20:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lweEBtF5Y2NYNgAAMHmgww (envelope-from ); Thu, 03 Nov 2022 08:20:33 +0000 Message-ID: <357d9e4e-a975-7198-a496-1832d1ade3e9@suse.com> Date: Thu, 3 Nov 2022 10:20:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] btrfs: fix match incorrectly in dev_args_match_device Content-Language: en-US To: Liu Shixin , Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20221103083301.626561-1-liushixin2@huawei.com> From: Nikolay Borisov In-Reply-To: <20221103083301.626561-1-liushixin2@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org On 3.11.22 г. 10:33 ч., Liu Shixin wrote: > syzkaller found an assert failed: > > assertion failed: (args->devid != (u64)-1) || args->missing, in fs/btrfs/volumes.c:6921 > > This can be trigger when we set devid to (u64)-1) by ioctl. In this case, > the match of devid will be skipped and the match of device may be succeed > incorrectly. > > Patch 562d7b1512f7 introduced this function which is used to match device. > This function contaions two matching scenarios, we can distinguish them by > checking the value of args->missing rather than check whether args->devid > and args->uuid is default value. > > Reported-by: syzbot+031687116258450f9853@syzkaller.appspotmail.com > Fixes: 562d7b1512f7 ("btrfs: handle device lookup with btrfs_dev_lookup_args") > Signed-off-by: Liu Shixin Reviewed-by: Nikolay Borisov > --- > fs/btrfs/volumes.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 94ba46d57920..bf2d886cfb4b 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -6918,18 +6918,18 @@ static bool dev_args_match_fs_devices(const struct btrfs_dev_lookup_args *args, > static bool dev_args_match_device(const struct btrfs_dev_lookup_args *args, > const struct btrfs_device *device) > { > - ASSERT((args->devid != (u64)-1) || args->missing); > + if (args->missing) { > + if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) && > + !device->bdev) > + return true; > + return false; > + } > > - if ((args->devid != (u64)-1) && device->devid != args->devid) > + if (device->devid != args->devid) > return false; > if (args->uuid && memcmp(device->uuid, args->uuid, BTRFS_UUID_SIZE) != 0) > return false; > - if (!args->missing) > - return true; > - if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) && > - !device->bdev) > - return true; > - return false; > + return true; > } > > /*