Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2630515pxv; Sun, 11 Jul 2021 20:45:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCllnN56C8mnV9LpOz3VJDkP0o9qRvMHDh1m2bYrj3xFY6oJAG6fzDJcku6ChQweFr4FhP X-Received: by 2002:a50:9b06:: with SMTP id o6mr63687343edi.284.1626061544971; Sun, 11 Jul 2021 20:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626061544; cv=none; d=google.com; s=arc-20160816; b=Rtq1KmTciWlKoLYU7sDk4XzWQnCeovt6Vts5ZFY8gPfLXOGTA3eTQdYM3PvUyoSa2v T8WYUVTTR6lyKd1boog2Eep5vrTjuiGD1Xw8fgQU+1egHIt9O7M5QghyYV8Q0y5FMsVh EcpP2dFv4Okv1P+FQZ0qc1zkL92tbGnkMatwcjJ8cYeou2dAiLb4FS5z3Z+xqI5uLbL8 TL9ihzPojKYrKM76xljoAE4s+VEIq1EJQnQ2tAbx3Myho2BjTW6wmWzlOJmGLxGKkFqr 0rpXaE2mlEFfLvtflCJ4aBjm7M29+Noi8Jjt3oJ816IE44cYLFiUDXfVCeDonAvecXl/ PMIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FNaAgJi+fq8ys+9B4sOf2Hdg4MkZwkLSB0lQ2Ck2TCQ=; b=vvKlN6x4q2AWyjC6hw1pCRB7wF5pZUh6JJza/yZqMbSbslkYX53+a+CdDay8UpVfoQ bkA0IrBx9aRHrYWg918iFliZss2GDBiWM1TZ4EzX8jIbBz2hB853EorMJOfdZTfx7o/s fiQMAwdKBACMVMTe7XzggmsDQAvte7WJzjPOhh1ig1/SBV5yEVo4yYgzkltitnx/DSx0 YQAap17Kw+EhfI4NGAH/4uMMCt/lr47RpGxyrz/TScTYdMpCFuuuO6AkGDID7Xb51vL6 K8FIzhQnk0JMoNnNVNZxb3497kuAGK2P7mZ2ZJz+Muzcn0ziUe5gukd04vB4ySUqaWYI 8EeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MlypPXS4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si15312011edx.496.2021.07.11.20.45.22; Sun, 11 Jul 2021 20:45:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MlypPXS4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233255AbhGLDrP (ORCPT + 99 others); Sun, 11 Jul 2021 23:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232580AbhGLDrP (ORCPT ); Sun, 11 Jul 2021 23:47:15 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D532C0613DD; Sun, 11 Jul 2021 20:44:28 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id x16so15093304pfa.13; Sun, 11 Jul 2021 20:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FNaAgJi+fq8ys+9B4sOf2Hdg4MkZwkLSB0lQ2Ck2TCQ=; b=MlypPXS4oN/FOvVKZJObV515kSpjtrHQAyEhmUy6GubTrZv9qB52SgcVTeO+nUkfSk wSaw1+dFmS5ay8WcsyjgOeTLfBnYfXPtSnqZOYnJuJNHUvq2ip7Ph4++4LkMLxqBnLR+ R5kQEQexTWga7ky6Z8Q1AZc+sB6yx5On1mqOcgOPrSuB211PMdQZ+r1hKCdyOxXTF9E6 8Hfudo3501rVSMUgNpq9CeifYmj70lhyS4HlLexxI3FmL80RuJMDn2GNKXkgIMOm0TV1 XKqLZY84+FjId+jzErP9mQeWTjA2wcoAb/IC27dmOSwcvUpR1ELQaYfY4+vbIKLIH6oJ drdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FNaAgJi+fq8ys+9B4sOf2Hdg4MkZwkLSB0lQ2Ck2TCQ=; b=cC8I/x8z/DVHYR7hHVspXDb/tF+kdC/RkUZNq9EO+pDt2JmyNnC0gyVVlkIiTQwLv/ e9Pqdl719q1zkHnG7BK+POYICg8xNcQuDLcCEcuVPfcjWfQcCFAdRhiYA41QIjIjGK4o RrNaEOMLSTg43KY65wdbZLwg1qayWhIRSjgkAGvtWEbhxKUrZlb7Y8e01R7MnhXNdg87 8/LYy8NdcFh77x4MaeUgWbq2P31iW6biI8kEJWVIFtrfIzeFnnE8bwOyE8/nB3dvo2w+ 3edAsFkpBL0/e6zR4NoHlkK8XODGedqbt65JB1v2ZfsHj5u74SGCfCz4cIBsO1H6VfSt gEpw== X-Gm-Message-State: AOAM530Pm56fQE0lnJLUADXK5Nkx18otW/GNLT/fbGD6eVt3x6wT+kz3 yixpb5ydeZ45DA5LZQyMptM= X-Received: by 2002:a63:5904:: with SMTP id n4mr50761789pgb.176.1626061467376; Sun, 11 Jul 2021 20:44:27 -0700 (PDT) Received: from fedora ([2405:201:6008:6ce2:9fb0:9db:90a4:39e2]) by smtp.gmail.com with ESMTPSA id x23sm12881302pgk.90.2021.07.11.20.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jul 2021 20:44:26 -0700 (PDT) Date: Mon, 12 Jul 2021 09:14:22 +0530 From: Shreyansh Chouhan To: Jan Kara Cc: rkovhaev@gmail.com, reiserfs-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Verify the items that we read from blocks Message-ID: References: <20210705113329.GE15373@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210705113329.GE15373@quack2.suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I thought that my last email wasn't an appropriate response, since to me it looked as if I hadn't read your suggestions before sending a response. (Couldn't quote anything because I wasn't able to find the email on mutt (messed up filters,) and had to write a quick email with the in-reply-to option.) So I thought I'd resend the response after I've fixed my inbox. On Mon, Jul 05, 2021 at 01:33:29PM +0200, Jan Kara wrote: > Hello! > > On Fri 02-07-21 20:35:41, Shreyansh Chouhan wrote: > > I was trying to work on this[1] bug. After a lot of reading the code and > > running it under gdb, I found out that the error happens because > > syzkaller creates a segment with raw binary data in the reproducer[2], > > that has the wrong deh_location for the `..` directory item. (The value > > is 0x5d (93), where as it should have been 0x20 (32).) > > First, I'd like to note that reiserfs is a legacy filesystem which gets > little maintenance and I think distributions are close to disabling it in > their default kernels if they didn't do it already. So I'm not sure how > much is it worth it to do any larger fixes to it. But if you have a > personal passion for reiserfs feel free to go ahead and try to fix these > issues. > I had already spent a considerable amount of time on the debugging portion, (to find an obvious mistake, now that I look back at it in hindsight,) so I thought I'd just send in a patch. > > I think that the solution would involve checking the items that we read, > > and verify that they are actually valid. But this check could actually > > happen in two places: > > > > - First idea would be to check as soon as we read a > > block, and one way of doing that would be adding a wrapper around > > ll_rw_block that validates the leaf node blocks that we read. The > > benifits to this would be that since we're solving the problem at it's > > root, very few functions would have to be changed. But I don't know > > how much of a performance hit would it be. > > It depends on how heavy the checks are going to be but generally checking > when loading from the disk is the way how most filesystems handle this. > The checks would be an O(n) traversal of directory headers, which themselves check if the deh_location is greater than item length. The item header checks were already present in the `is_leaf`(?) function. > > - Second idea would be to do these validation checks lazily. This should > > be faster than the first idea, but this would involve changing the > > code at more places than in the first idea. > > > > For how the validation happens, the first idea that comes to mind is > > reading the item headers from the block that we read and verifying if > > the header is valid, and if the items themselves are valid according to > > the header. > > Looks sound. > I have added the implementation for the above idea to the `is_leaf` function. Thanks a lot for your suggestions. > Honza > -- > Jan Kara > SUSE Labs, CR Thanks, Shreyansh Chouhan