Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1206576rwb; Fri, 18 Nov 2022 14:35:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf74+t8EtLOZGw0PYC70VAg/mFe+Z/mERg76+FKaj5/jUvqD8wx4MHXFLrqAZoDklJVMm0t9 X-Received: by 2002:a17:90b:3d84:b0:213:f8a9:fd49 with SMTP id pq4-20020a17090b3d8400b00213f8a9fd49mr9844837pjb.73.1668810917395; Fri, 18 Nov 2022 14:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668810917; cv=none; d=google.com; s=arc-20160816; b=JRm5wxJcM6fMc1M6ErRIhfznjiAhFGLcRdG2bdCMovpcPwV53kzzN9RGM+zPjNYmoE dgUWiV7mfDDiOEWI/KH83bHOD8QOT3sig27q4LQoAtk9dNG2UxEpZO/gCZgS69Q4O7vK NxweEav3BLSX7DscIj0y77PqqmYrP1UTINPhDfprL0oQaFClRxpxYZ36tqab3cXjjCaP St4bxGeu+ihQboIclUVgmZzB5jWbfOJo6Ss/dnx2xUmci8M/CMfcKSNl9dIur/kV9JYl W/l23rgZI0LeKGQuu5Z42n/pI2tF+LZ/0KLj/yeBVTtbu4Ycg9z2vQB9NIoKyNWiSMoh vuqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=U/aVSPg6iZDwlHXMjTyIWn2+f8tzBAqlfsNUiOudOqs=; b=DrwuapCTy8pqJm1D+lgtTCtlRwAMZkalRCLnNX9aqbFmA37/JXDoQo5ox0ZhRD383c wo7q7OWFTnq/3z2AHdYwyQzqYmgva1+mIieHUcMK5utDDsxYfaHfPeuSBmSDtz5MjQp6 xoPDSxd+p/VfxTDgoUwMSWFYnnS299ed5Bj/1DPDiRZ2w/2jRQvBNngsLkA51xNdPfk9 cA4qgoP29CCqvo4xq7pfLmJ2P/bgC58PexwQg7Mv6H3y6Dczk4shdToXYDe274oFUmYI /9VAar7yLpXX0NAffgIT0XpILvpuW4GiRcVYpUEqSvdmDfUJhxsxEJKJAflhZ/VerOaB izbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EZ7+sTS7; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a1709028f8700b0017f908814c6si4306503plo.532.2022.11.18.14.34.57; Fri, 18 Nov 2022 14:35:17 -0800 (PST) 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=@linux-foundation.org header.s=korg header.b=EZ7+sTS7; 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 S231179AbiKRWMJ (ORCPT + 90 others); Fri, 18 Nov 2022 17:12:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbiKRWLt (ORCPT ); Fri, 18 Nov 2022 17:11:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 157A9976FA; Fri, 18 Nov 2022 14:11:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BE899B8255C; Fri, 18 Nov 2022 22:11:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62FEEC433D6; Fri, 18 Nov 2022 22:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1668809499; bh=+7RUpCopDWImHx4kpniYvLBKqUGp3uhYcB86V79wOq4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EZ7+sTS7ME+VOF+J/iDcMwXeLNFmhd8HaBTNKMqfdJkqrtUnhUme/VUqiwmbXvMN8 ZcI4DwDYHr91Q86B4xAC92PwVRdbDaZZMceC0PHTDYx3N7dw7zB8NnvoU1djVryuie iM4Ktss2tX/23xa47RJ/jnhF1e/Tt4r/YCuRQPhU= Date: Fri, 18 Nov 2022 14:11:38 -0800 From: Andrew Morton To: Chen Zhongjin Cc: , , Subject: Re: [PATCH] nilfs2: Fix nilfs_sufile_mark_dirty() not set segment usage as dirty Message-Id: <20221118141138.c091445bdda36b78f6277c1f@linux-foundation.org> In-Reply-To: <20221118063304.140187-1-chenzhongjin@huawei.com> References: <20221118063304.140187-1-chenzhongjin@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, 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 Fri, 18 Nov 2022 14:33:04 +0800 Chen Zhongjin wrote: > In nilfs_sufile_mark_dirty(), the buffer and inode are set dirty, but > nilfs_segment_usage is not set dirty, which makes it can be found by > nilfs_sufile_alloc() because it checks nilfs_segment_usage_clean(su). > > This will cause the problem reported by syzkaller: > https://syzkaller.appspot.com/bug?id=c7c4748e11ffcc367cef04f76e02e931833cbd24 > > It's because the case starts with segbuf1.segnum = 3, nextnum = 4, and > nilfs_sufile_alloc() not called to allocate a new segment. > > The first time nilfs_segctor_extend_segments() allocated segment > segbuf2.segnum = segbuf1.nextnum = 4, then nilfs_sufile_alloc() found > nextnextnum = 4 segment because its su is not set dirty. > So segbuf2.nextnum = 4, which causes next segbuf3.segnum = 4. > > sb_getblk() will get same bh for segbuf2 and segbuf3, and this bh is > added to both buffer lists of two segbuf. > It makes the list head of second list linked to the first one. When > iterating the first one, it will access and deref the head of second, > which causes NULL pointer dereference. > > Fixes: 9ff05123e3bf ("nilfs2: segment constructor") Merged in 2009! > --- a/fs/nilfs2/sufile.c > +++ b/fs/nilfs2/sufile.c > @@ -495,12 +495,18 @@ void nilfs_sufile_do_free(struct inode *sufile, __u64 segnum, > int nilfs_sufile_mark_dirty(struct inode *sufile, __u64 segnum) > { > struct buffer_head *bh; > + void *kaddr; > + struct nilfs_segment_usage *su; > int ret; > > ret = nilfs_sufile_get_segment_usage_block(sufile, segnum, 0, &bh); > if (!ret) { > mark_buffer_dirty(bh); > nilfs_mdt_mark_dirty(sufile); > + kaddr = kmap_atomic(bh->b_page); > + su = nilfs_sufile_block_get_segment_usage(sufile, segnum, bh, kaddr); > + nilfs_segment_usage_set_dirty(su); > + kunmap_atomic(kaddr); > brelse(bh); > } > return ret; Do we feel that this fix should be backported into -stable kernels?