From patchwork Mon Oct 17 10:04:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hoi Pok Wu X-Patchwork-Id: 3367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1363554wrs; Mon, 17 Oct 2022 03:09:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xau0aUaXqBhvSPK2TiBEacjgSdz3X7zEgNCtB48+5T+w/zIlDWz3ylwMMvPntZc46VC9+ X-Received: by 2002:a17:906:730d:b0:78e:9ca5:3269 with SMTP id di13-20020a170906730d00b0078e9ca53269mr7665001ejc.366.1666001372485; Mon, 17 Oct 2022 03:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666001372; cv=none; d=google.com; s=arc-20160816; b=jDclaoUDZT/pf131OCY8uWMB6atPLI776FMcuyF7prLk5KqP/Q/mKmd/ieIbFAylVT zP78HD+K54dFqh71ZKqRfPvkamHjr1HeuLWdUsUldsiVfI8D7V7Vuz3wS108mpgr8nPa t5wv5hZejysoRkb2kDUjfNvTOBx/eO8iKZhdyU9OKg7k3n8q2uAkCMfZ/dN0++/nHsKl ++b3wVA01ocug1WPQ30+FwDTciGs6TQlnAXNBnos0ns5ThgvG1VjTiDZ6mzWfYOUunfN 3Qbo70KPmJHtoFT68MJ6m8jl3rvyrxnzW4fKjIPRWXGx0IgudCnxoYHmJtqBFNT5YCPS HDcg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=RuPi2kJWnTKaT4aVfokzpN9MYv+IdW9MQr50PHecKpc=; b=Ahl6izYK1rziVPJH5rEbTfpETduB5bLbv+tjytRWkJ9gfkx0NYTxtal8LqTx5A/ygk nDAMGBwO89VIW8wcr5vpIvAwxJ/PQDhGCcVLHnNguB1Un7dN1Xr9HYz6APoEr3i9DWqi 4DhT6KWVvqgZb+XdEKxfc0ROLlAfjOI4DrERuz2nZdmoPSssSKKGFi9RFtLVs2CQjOyn VcYKOkYQvmJTB+uD4yOR63k4F15hO515pdwvz4VzjClF1YXV67XWAE6b/tZxIiF9wQnA rV+0ViGPCKsKTso5UtamwQZVZ/pn+O58TIR72nS8+hBCC9UKz4uE/n2y9Up0U92tiMYH Q9TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YqrS+att; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg15-20020a170907970f00b0078d426c2844si9301041ejc.213.2022.10.17.03.09.02; Mon, 17 Oct 2022 03:09:32 -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=@gmail.com header.s=20210112 header.b=YqrS+att; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbiJQKFH (ORCPT + 99 others); Mon, 17 Oct 2022 06:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbiJQKE6 (ORCPT ); Mon, 17 Oct 2022 06:04:58 -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 08CE61EEE8 for ; Mon, 17 Oct 2022 03:04:50 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id p14so10636578pfq.5 for ; Mon, 17 Oct 2022 03:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RuPi2kJWnTKaT4aVfokzpN9MYv+IdW9MQr50PHecKpc=; b=YqrS+attN7r6MY97eZcauP2HvFXu4WYJG9YWeF68qJKfCeX4QvaDqnSIf7HRVaCGBu dyfX63Th9wv9ekjiN4sNRwIFAJOIH8V4CW4DoGjI3E7NrGgyqpxqX+Gb5LVgxMrT5iph kp6diM4a3u4zvnIh9+qT9M+bISfNBPi8ilhCdN3gfZRoX92oalbeY8NOo61j4icEA/LU TUl+caQH8o+IfOQx/Gr6iJFRzWFJPl+UVKH7dEsC69z1Fe5CI6CfnwEUnXtLFS62gjmj I6WvoOaJkOq2dj2Tj2qjCVWcvVNYoBZLQd7VkGTI0YotieAGsHB8qRroUGsYyI6JNS3Q 9Lrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RuPi2kJWnTKaT4aVfokzpN9MYv+IdW9MQr50PHecKpc=; b=65VFBUC3qg+GRhN9diKHEPQbKR0k+a4ZM8I7eCnfjpjRwU1ycrejG4pYqxC2VgF94v ctuTrmprKOh9pX2Ch0zU4CKf2PCM5+OoD0pQ12ud8udMuGl6yFw7f4L4pu1wjWUHiYuX p9bJO6NCmkC8pmPqxNb2aeAF6XJwnWaeTlSzrhhyGEeuYBD99lzb026Yr/3k9uhckILT z5WeIwC1GuQ8AKFjrfHjeNSnPtZDBdjNQiNzJ6MaRS+xgOxYOXXrSbvOyoruLCHVLwdf o1z/M7sa+ZY7gs3a5XWkcn9QTm+U6ekV5yWBeuJPLk57+cuKp7/a44EJwbb1OAO1qXZ5 RRRQ== X-Gm-Message-State: ACrzQf3mE0ivnv/fyLzF1Ed8c6cib1BqrA0639QpcEfDKu7YeqwsmyPB Ef7cfiLn4hsvBn7t2ySOT6Q= X-Received: by 2002:a63:5658:0:b0:43c:dac:9e24 with SMTP id g24-20020a635658000000b0043c0dac9e24mr9915160pgm.562.1666001089618; Mon, 17 Oct 2022 03:04:49 -0700 (PDT) Received: from localhost.localdomain (124244014158.ctinets.com. [124.244.14.158]) by smtp.gmail.com with ESMTPSA id d8-20020a170902cec800b0017f7b6e970esm6248454plg.146.2022.10.17.03.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 03:04:49 -0700 (PDT) From: Hoi Pok Wu To: jaegeuk@kernel.org, chao@kernel.org Cc: Hoi Pok Wu , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+035a381ea1afb63f098d@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH] fs: f2fs: fix kernel discard_thread NULL dereference Date: Mon, 17 Oct 2022 18:04:37 +0800 Message-Id: <20221017100437.618363-1-wuhoipok@gmail.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746929055089551418?= X-GMAIL-MSGID: =?utf-8?q?1746929055089551418?= Pointer discard_thread is pointing to nowhere, using IS_ERR prevents the situation. IS_ERR also seen being used throughout the file. Link: https://syzkaller.appspot.com/bug?id=9499bc6574cea5940e48199c2fd0732d9b11e5e1 Reported-by: syzbot+035a381ea1afb63f098d@syzkaller.appspotmail.com Signed-off-by: Hoi Pok Wu --- fs/f2fs/segment.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index acf3d3fa4363..79978b7206b5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1634,7 +1634,8 @@ void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi) struct task_struct *discard_thread = dcc->f2fs_issue_discard; dcc->f2fs_issue_discard = NULL; - kthread_stop(discard_thread); + if (!IS_ERR(discard_thread)) + kthread_stop(discard_thread); } }