Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp329736rdb; Wed, 17 Jan 2024 03:27:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJpzeHdzWqq1TA4Aofkxl2T5rUzI+ZUkx7/fczEM3wsOdcX7Tz2zu2Dxn/Z28F0vHpD7nw X-Received: by 2002:a05:620a:ce2:b0:783:46d3:9426 with SMTP id c2-20020a05620a0ce200b0078346d39426mr9393209qkj.12.1705490865844; Wed, 17 Jan 2024 03:27:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705490865; cv=pass; d=google.com; s=arc-20160816; b=v3xS0BUqDVy1kY1iDFQ+d/OVrJ1Z7ODxOtVZPrFPORTcI8TEPl+2s2Dx0KywF3XEfg gXlHoVoTmSCrv37JH8jlQTZ66pWJ3gfZDa6XFO/5VeNOGx1JuvVehDYTiVAqLZb3UHOf bbLkgNsNmY9UUGdsf4cTdFfw+ESVum1viw1PhdomT4l0gwdQBLQBUcnSMBfOLXUDMi7J aQfZfwhbdv/9FgMCZ/B2C8Ax9/J3MyBOEiBE0xIt5kGbmbN8TCRzZUCpD7Nfl/yQk89r HCtc0225on6NVjFILotDSECg0O3ShGox+md4BaXzdRSQ/BanTBUsHuRQxM+umWiqAJLb +ahg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=yX7YAU0jZ00+RmLgD3hlICEdBYU3XjNXhe6NXBaxDVg=; fh=iSTvwZmjU5IlIVs2I/EpJZRkDxfPJrAnqTeFpoFXsW4=; b=WIZYgzEuid+/81f1RQ4OxZ6RgNqIpCybDMgEITa2t8Y84tsVzI7XZpkgj6NFRal2k9 RrNeB4WrRzi9Mb9pUDz5nMPcLZJX8y7RqDA/49a9AcKvn+Exkg6VIF1K/O38GSojtG1x /VFVh37v8uKyfjYoIa//ICT5gf/hbV+0rvXAyAgw0jGImn7cdR87yE3CTrN+vr1hCPny +GuE7t9OZgY0QjXJb8sDaYDZa+LIvAEz7iD57DxFDkAGHZ0d9QrkjlTeeevPH5GmhwXo GvBQGTlEdkKmP97GTNL3OnUULNbsFo+wz2qHsrYUJ1wjeJed8WcDmYfBwEIHxmoNPeUn eIaw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hCmspbtP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-28911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w21-20020a05620a445500b007835aea7e49si6688345qkp.362.2024.01.17.03.27.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 03:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hCmspbtP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-28911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 771241C213A1 for ; Wed, 17 Jan 2024 11:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BEC61DDF5; Wed, 17 Jan 2024 11:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hCmspbtP" Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC2F21DDEA for ; Wed, 17 Jan 2024 11:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705490859; cv=none; b=G6GEUypyROpgJ2gpplPEhXHOBCtDj3z7LHRseaDntoe8MZfqg0VDGDhMSZVgFTeA94rl0f5xUm0AX/TY1X9igQnbouE0ZQIEQT3SQQX/Sf3fab5Z0jgdL2LryJgtpW6uVulitJqtiIvJ9wZcmdeHcN0Hbqh0oRI9QTvCIDPsqWY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705490859; c=relaxed/simple; bh=1OR+xPZ6Pg7n5BBFW9SfbEotYULYikt0P7tLlgmn9WM=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version: References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc: Content-Type:Content-Transfer-Encoding; b=li83IV9MQWoLwSQiYMBTVA/X1DgN5TSHr4v5a4GiHdWm/xQKEDOvwGCc4l7iQxQLuWohiSWgxIExV8E7X2jRes3RZFmwNUyawuhr3iFxMJaa71W43wO4j0ufm+aBsMaHG+7MDz1j9zmGWtOQs0V5QMLjYp2O/TAMVapZkT3DqKw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hCmspbtP; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-783045e88a6so809250985a.0 for ; Wed, 17 Jan 2024 03:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705490857; x=1706095657; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yX7YAU0jZ00+RmLgD3hlICEdBYU3XjNXhe6NXBaxDVg=; b=hCmspbtP8ajmmpWt2s8MLVUjUDkWRUsDXxlcg076ye1i2tydgjka9Ckeii0bvo63LI sIK7bV8roxYaS9Vsl2ZxCQwhy93LbEJobFWAO5wtQvrIYBcKF3MBCZyWAcBZ7hvNQhCt CCLMkB70cKVWTBE9+op8MUMJlLS3fgia/9WIuwjcz7IsgnqcW8gRJgWNIFy+jjtIxAgt dd6czHZiWqLdXRPbDRDeR0+GMARyeUChBQWNU9MkZq8oCZZjwrDqYeJ/4eXuDHgZ+SE2 Ka87Zyb3uausekrEUBKyR9VEoellZr1wGO+jDQNjN/C/J76slf8OA0DkFnqA9TG8ux0O VFlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705490857; x=1706095657; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yX7YAU0jZ00+RmLgD3hlICEdBYU3XjNXhe6NXBaxDVg=; b=WjgJFaxKRra1fmyb4qjN/UjBwO2QPWg0V70F70pUHbdjTh8SepkPzMM4mpL/SdrcaF AhxrM64ShesQtAVC4g4GsIrK5sMye0k1NilAL/g2lxIoCHpvgmJVMsYnN8v+irnNUtNl 5MTg21R286L13TTGw0b/pgO1pr8EDOsae5TkSsQWYY+CFmS7xVj3NmX1GCBoWwxP4hI+ YOz5B7oW6cZnVuRxS+qehGU+6IOcnjWI+aFnKKtgKupGZwcW6pD8cvVAy5/sV7H+ngEz 1x9tZBsvcDLtZd/sP0yLaOwf4oHEDL/EEx02wR6l0CW8NMoMAU0iLKg5zQ3MTBhLFPBo X/Aw== X-Gm-Message-State: AOJu0YzzVb16O/bBG67THBVD7k6nEZ4dU1gJdTY9jelJv2ZZBat/7q8a 52WZu6kQE8jN/bollIPpnwkocFbhOKauGrGx/Co= X-Received: by 2002:ac8:4e96:0:b0:42a:de7:3244 with SMTP id 22-20020ac84e96000000b0042a0de73244mr984144qtp.59.1705490856737; Wed, 17 Jan 2024 03:27:36 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240116141138.1245-1-qwjhust@gmail.com> <601da6d0-8e22-4e6f-a791-5db9d5ebc793@oppo.com> In-Reply-To: <601da6d0-8e22-4e6f-a791-5db9d5ebc793@oppo.com> From: Wenjie Qi Date: Wed, 17 Jan 2024 19:27:26 +0800 Message-ID: Subject: Re: [f2fs-dev] [PATCH v1] f2fs: fix NULL pointer dereference in f2fs_submit_page_write() To: Yongpeng Yang Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org, hustqwj@hust.edu.cn, linux-f2fs-devel@lists.sourceforge.net, chao@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Yongpeng, I don't think that's correct. If list_empty(&io->io_list) and fio->in_list are true, it will jump to the "out" label. This does not enter the judgment process. In addition, __bio_alloc() will ensure that io->bio ! =3D NULL. On Wed, Jan 17, 2024 at 6:17=E2=80=AFPM Yongpeng Yang wrote: > > Hello Wenjie, > This patch does not prevent the simultaneous truth of > list_empty(&io->io_list), fio->in_list, and is_end_zone_blkaddr(sbi, > fio->new_blkaddr). NULL pointer dereference error still exists in > =E2=80=9Cbio_get(io->bio)=E2=80=9D. Is that correct? > > On 1/17/2024 9:39 AM, Wenjie Qi wrote: > > Hello Daeho, > > I don't think moving just the "out" label will work. > > If a fio is zone end and in_list =3D 1, that fio is missed without bein= g judged. > > > > On Wed, Jan 17, 2024 at 5:58=E2=80=AFAM Daeho Jeong = wrote: > >> > >> On Tue, Jan 16, 2024 at 6:13=E2=80=AFAM Wenjie Qi = wrote: > >>> > >>> BUG: kernel NULL pointer dereference, address: 0000000000000014 > >>> RIP: 0010:f2fs_submit_page_write+0x6cf/0x780 [f2fs] > >>> Call Trace: > >>> > >>> ? show_regs+0x6e/0x80 > >>> ? __die+0x29/0x70 > >>> ? page_fault_oops+0x154/0x4a0 > >>> ? prb_read_valid+0x20/0x30 > >>> ? __irq_work_queue_local+0x39/0xd0 > >>> ? irq_work_queue+0x36/0x70 > >>> ? do_user_addr_fault+0x314/0x6c0 > >>> ? exc_page_fault+0x7d/0x190 > >>> ? asm_exc_page_fault+0x2b/0x30 > >>> ? f2fs_submit_page_write+0x6cf/0x780 [f2fs] > >>> ? f2fs_submit_page_write+0x736/0x780 [f2fs] > >>> do_write_page+0x50/0x170 [f2fs] > >>> f2fs_outplace_write_data+0x61/0xb0 [f2fs] > >>> f2fs_do_write_data_page+0x3f8/0x660 [f2fs] > >>> f2fs_write_single_data_page+0x5bb/0x7a0 [f2fs] > >>> f2fs_write_cache_pages+0x3da/0xbe0 [f2fs] > >>> ... > >>> It is possible that other threads have added this fio to io->bio > >>> and submitted the io->bio before entering f2fs_submit_page_write(). > >>> At this point io->bio =3D NULL. > >>> If is_end_zone_blkaddr(sbi, fio->new_blkaddr) of this fio is true, > >>> then an NULL pointer dereference error occurs at bio_get(io->bio). > >>> The original code for determining zone end was after "out:", > >>> which would have missed some fio who is zone end. I've moved > >>> this code before "skip:" to make sure it's done for each fio. > >>> > >>> Signed-off-by: Wenjie Qi > >>> --- > >>> fs/f2fs/data.c | 8 ++++---- > >>> 1 file changed, 4 insertions(+), 4 deletions(-) > >>> > >>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > >>> index dce8defdf4c7..4f445906db8b 100644 > >>> --- a/fs/f2fs/data.c > >>> +++ b/fs/f2fs/data.c > >>> @@ -1080,10 +1080,6 @@ void f2fs_submit_page_write(struct f2fs_io_inf= o *fio) > >>> io->last_block_in_bio =3D fio->new_blkaddr; > >>> > >>> trace_f2fs_submit_page_write(fio->page, fio); > >>> -skip: > >>> - if (fio->in_list) > >>> - goto next; > >>> -out: > >>> #ifdef CONFIG_BLK_DEV_ZONED > >>> if (f2fs_sb_has_blkzoned(sbi) && btype < META && > >>> is_end_zone_blkaddr(sbi, fio->new_blkaddr)) = { > >>> @@ -1096,6 +1092,10 @@ void f2fs_submit_page_write(struct f2fs_io_inf= o *fio) > >>> __submit_merged_bio(io); > >>> } > >>> #endif > >>> +skip: > >>> + if (fio->in_list) > >>> + goto next; > >>> +out: > >> > >> How about moving only the "out" label instead of the whole block from > >> "skip" to "out"? > >> > >>> if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || > >>> !f2fs_is_checkpoint_ready(sbi)) > >>> __submit_merged_bio(io); > >>> -- > >>> 2.34.1 > >>> > >>> > >>> > >>> _______________________________________________ > >>> Linux-f2fs-devel mailing list > >>> Linux-f2fs-devel@lists.sourceforge.net > >>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > > > > > > _______________________________________________ > > Linux-f2fs-devel mailing list > > Linux-f2fs-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel