From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D808DC43217 for ; Fri, 21 Oct 2022 02:41:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 379858E0002; Thu, 20 Oct 2022 22:41:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 329CB8E0001; Thu, 20 Oct 2022 22:41:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F16E8E0002; Thu, 20 Oct 2022 22:41:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0DC428E0001 for ; Thu, 20 Oct 2022 22:41:19 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D01CE1C6470 for ; Fri, 21 Oct 2022 02:41:18 +0000 (UTC) X-FDA: 80043405036.02.E8DCA7C Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf24.hostedemail.com (Postfix) with ESMTP id 8523F180019 for ; Fri, 21 Oct 2022 02:41:18 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id 3so1314741pfw.4 for ; Thu, 20 Oct 2022 19:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hHaTEgELqZucdbkgwdj5xVLrR3sTANCQHwBWYpXrDwg=; b=dn1FJWNAP+t44tpnfehnU21uXU5pdAaACu3Oa79rz0ubMUQKxXq5xEKNle55fcNpNr k1/muB+8CtaMnBgpWGzHI/67dp1Y0IBmwFn44HrvW5DlW9v+X+CGhPnrkWEiAjfg+2QQ aZDzR9Bdf8jk/5zW3Ic0OW+3tHEXLBdAf2JY5vuYHQjkhm+uvnXHvO0e77cavyq9BoML CD8xq2DJNbVRw20lnq3wrGiGcfqqcZP/nR8lokGzfL94W4LzLrAg019frrTS0sfeVJXA X3DVCPXyUtxQyufXAKsnJpYj4EZYx4IYZPIZOiXkYQgKbet34Bk8EHh0ysa7vGLhjGBj SzXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hHaTEgELqZucdbkgwdj5xVLrR3sTANCQHwBWYpXrDwg=; b=xUkApz4YvBFpWLZfwOnQUTgaSQ0+U9WVbxO8cxDsnisHm/7Ep8OmEVDgvlJVkIXRab sx0Wd2poAVGXrhVzHNnv8DlfrXWLyhU/FWINU9QvBOzllfDQ/sOZAHbcqLFzl+FeT11y nge3ePvqTgMxFpGiSU82xhdOlVAJ0H2BDsAEB5zoiFgPLU/ARVNHLYihT+aGaqqSmadD dleXnD8Po/Fs5CRiEzgBK8IxFRwFweFk0NJye/ij/F/3Rozv/Q+wj98nJQWvZnF0ftRo c8waep4iLHtOTq+/iB4VgmrgSFoB9X57uicUWpHkFbMaysi03Si0H3Rsxn1li2ja1P7F XKKA== X-Gm-Message-State: ACrzQf2cAYBiR0joDoTnSFh5GMY6M53os0v95WhrB69XVpe1FzeDdlbO zrsKlOw4CSQTw+rocZtCRLE= X-Google-Smtp-Source: AMsMyM6PtbI8J6Oapq5CSGQIqVaxBmmc+AT2patlNedL5QjRuHQN6mBD3iXGD0ZH3+VFJhwWx4zSiA== X-Received: by 2002:a63:1609:0:b0:45c:7c1c:4e7d with SMTP id w9-20020a631609000000b0045c7c1c4e7dmr14170938pgl.265.1666320077331; Thu, 20 Oct 2022 19:41:17 -0700 (PDT) Received: from localhost ([159.226.94.113]) by smtp.gmail.com with ESMTPSA id d11-20020a170902cecb00b00177fb862a87sm13725924plg.20.2022.10.20.19.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 19:41:16 -0700 (PDT) From: Hawkins Jiawei To: mike.kravetz@oracle.com Cc: 18801353760@163.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, songmuchun@bytedance.com, syzbot+a3e6acd85ded5c16a709@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, yin31149@gmail.com Subject: Re: [PATCH -next] hugetlbfs: fix null-ptr-deref in hugetlbfs_parse_param() Date: Fri, 21 Oct 2022 10:37:41 +0800 Message-Id: <20221021023740.184533-1-yin31149@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666320078; a=rsa-sha256; cv=none; b=nNsrQa9I64d6+oj8CE6OgMMOTa3b6Ya3EeopA+EVLUgER1ZJbrTQiTlT03beWPv36S4tfU QzHPES68UXVOoabBZusX7COhl63jAdqWCaRyw+uTky3926TQMbShIxR59HDwZ1NayLX7YW U14ASCMjVOzloosbkjSpCeOHwkMPKYY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dn1FJWNA; spf=pass (imf24.hostedemail.com: domain of yin31149@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=yin31149@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666320078; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hHaTEgELqZucdbkgwdj5xVLrR3sTANCQHwBWYpXrDwg=; b=RuCUM1x8NhNMShkk4VXkKOKgAcIiIHX38NaRkwjxmE2Vz7Navq4uFmFUFEkL2MjDQAt5Nv 5DSmTHyH2LT/O26y2FNyJEAfIEFX9h76PBUJBUKBCSD66Uy+B6Vi80Qzo0yLEZlCcV8U1j OGn/XXj3JJ5U2Far2+9MBZWTmacY8os= X-Stat-Signature: jeief4wdqcgw546pk4fjyuakgayj1yxk X-Rspamd-Queue-Id: 8523F180019 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dn1FJWNA; spf=pass (imf24.hostedemail.com: domain of yin31149@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=yin31149@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1666320078-480957 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Mike, On Fri, 21 Oct 2022 at 07:38, Mike Kravetz wrote: > > On 10/21/22 07:16, Hawkins Jiawei wrote: > > Syzkaller reports a null-ptr-deref bug as follows: > > ====================================================== > > KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] > > RIP: 0010:hugetlbfs_parse_param+0x1dd/0x8e0 fs/hugetlbfs/inode.c:1380 > > [...] > > Call Trace: > > > > vfs_parse_fs_param fs/fs_context.c:148 [inline] > > vfs_parse_fs_param+0x1f9/0x3c0 fs/fs_context.c:129 > > vfs_parse_fs_string+0xdb/0x170 fs/fs_context.c:191 > > generic_parse_monolithic+0x16f/0x1f0 fs/fs_context.c:231 > > do_new_mount fs/namespace.c:3036 [inline] > > path_mount+0x12de/0x1e20 fs/namespace.c:3370 > > do_mount fs/namespace.c:3383 [inline] > > __do_sys_mount fs/namespace.c:3591 [inline] > > __se_sys_mount fs/namespace.c:3568 [inline] > > __x64_sys_mount+0x27f/0x300 fs/namespace.c:3568 > > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > > do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 > > entry_SYSCALL_64_after_hwframe+0x63/0xcd > > [...] > > > > ====================================================== > > > > According to commit > > ac369cdd9448("vfs: parse: deal with zero length string value"), > > kernel will sets the param->string to null pointer in > > vfs_parse_fs_string() if fs string has zero length. > > > > Yet the problem is that, hugetlbfs_parse_param() will > > dereference the param->string, without checking whether it > > is a null pointer. To be more specific, if hugetlbfs_parse_param() > > parses an illegal mount parameter, such as "size=,", kernel will > > constructs struct fs_parameter with null pointer in > > vfs_parse_fs_string(), then passes this struct fs_parameter to > > hugetlbfs_parse_param(), which triggers the above > > null-ptr-deref bug. > > > > This patch solves it by adding sanity check on param->string > > in hugetlbfs_parse_param(). > > > > Reported-by: syzbot+a3e6acd85ded5c16a709@syzkaller.appspotmail.com > > Tested-by: syzbot+a3e6acd85ded5c16a709@syzkaller.appspotmail.com > > Link: https://lore.kernel.org/all/0000000000005ad00405eb7148c6@google.com/ > > Signed-off-by: Hawkins Jiawei > > Thank you! > > This was on my list of things to look at. > > Do you know if the issue existed before commit ac369cdd9448? Just > wondering if we need a Fixes tag and stable backports. This issue did not exist before commit ac369cdd9448, because kernel will sets param->string a string(although a zero length string) by kmemdup_nul() when fs string has zero length in vfs_parse_fs_string(). So it will ensures that param->string is not a null pointer in hugetlbfs_parse_param(). I also revert commit ac369cdd9448 or reset to ac369cdd9448~, and test the syzkaller reproducer. The reproducer does not trigger any issue in both situations. > > I'll take a closer look at the patch a bit later, unless someone beats > me to it. > -- > Mike Kravetz > > > --- > > fs/hugetlbfs/inode.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > > index 7f836f8f9db1..3ee84604e36d 100644 > > --- a/fs/hugetlbfs/inode.c > > +++ b/fs/hugetlbfs/inode.c > > @@ -1377,7 +1377,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par > > > > case Opt_size: > > /* memparse() will accept a K/M/G without a digit */ > > - if (!isdigit(param->string[0])) > > + if (!param->string || !isdigit(param->string[0])) > > goto bad_val; > > ctx->max_size_opt = memparse(param->string, &rest); > > ctx->max_val_type = SIZE_STD; > > @@ -1387,7 +1387,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par > > > > case Opt_nr_inodes: > > /* memparse() will accept a K/M/G without a digit */ > > - if (!isdigit(param->string[0])) > > + if (!param->string || !isdigit(param->string[0])) > > goto bad_val; > > ctx->nr_inodes = memparse(param->string, &rest); > > return 0; > > @@ -1403,7 +1403,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par > > > > case Opt_min_size: > > /* memparse() will accept a K/M/G without a digit */ > > - if (!isdigit(param->string[0])) > > + if (!param->string || !isdigit(param->string[0])) > > goto bad_val; > > ctx->min_size_opt = memparse(param->string, &rest); > > ctx->min_val_type = SIZE_STD; > > -- > > 2.25.1 > >