Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3290637imu; Sat, 24 Nov 2018 02:00:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/UG7BnBK+AVOvo3NzUvzpcwbadiuiSVNQxFiZ1YHrL4+FZUGm0/UEGYIyZeNWqiVMA39xhA X-Received: by 2002:a17:902:9a02:: with SMTP id v2mr19730684plp.180.1543053628572; Sat, 24 Nov 2018 02:00:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543053628; cv=none; d=google.com; s=arc-20160816; b=Zxvot4G8HIKx3nlgY4/wScaPR7jHj9D4CSUsoVUA2Ku5jcajJxCSMepL6Ffu/v9F0R qJ1fgxlbfx5Zi5+PzjYcsRa8W8UnkBy4/HuwdrFWxXhFYnfGPt9I9lnw9DVAZxDrkozI nO1rzVAFguJud2kLV4MwjhJS4Vg0Jk9QsX8eASrLuhtp9dWXXtVkj2HxUA64WtPyol/t Hfb9xgCo33Xk0gFEd9VE6VdQIB1dPlqKix+TVNbM4qqLN8n7DE+AQzGlQHIiX56mQRQH HhvIxPF2LjUdSLf4eegXP0yQ2s4mvr5hEx4r5vNom6KIhcUjES1kHKqPQIT80NZLmIvm kYUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=+rk2yFPDhKNq5W6RMA9/YN3WDZhiBqnkuKHHhux+ccY=; b=OgjOU9m7H7QRJ7plrpfjKqLHAQNK5VKuHAuzlPh3kaZglZq3JyUKWYNCynVoRPtXc4 zHn2M16hGdPK1MUwsA8mS0PBq1CCMHvtNHyFuz8syAhzueiLXtc4GxzbsiIl9yAeAoZG 4ViyNvFSFf93EuV6eFe98n0hyZyshxcj03ogLIo/48oAQRUsTE/GJj/fgo/kac3TkEYt hIwDdV325H2BYTn1hW54ZtDidOYxBJSNRSvL6LesXr6tDbc4IriGTRVxxTS8VMEzRHh6 joxcoeNJBzICrWSZXV8TcT5Brj6Mknrzuw1oHbBzJx1o+Q2ET5hjCIDr8wZDlgcKnMDS X26w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11si55915916pgi.324.2018.11.24.02.00.13; Sat, 24 Nov 2018 02:00:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbeKXUre (ORCPT + 99 others); Sat, 24 Nov 2018 15:47:34 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:36169 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725940AbeKXUre (ORCPT ); Sat, 24 Nov 2018 15:47:34 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 505FB53A07F94; Sat, 24 Nov 2018 17:59:28 +0800 (CST) Received: from [127.0.0.1] (10.134.22.195) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.408.0; Sat, 24 Nov 2018 17:59:21 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs: check memory boundary by insane namelen To: Sheng Yong , Jaegeuk Kim , , References: <20181115075040.83500-1-jaegeuk@kernel.org> <3d213d40-a4b0-6e60-87b2-81e66866ac4c@huawei.com> From: Chao Yu Message-ID: <1d801acd-ed1e-3593-45e6-ad71b27e4c7a@huawei.com> Date: Sat, 24 Nov 2018 17:59:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <3d213d40-a4b0-6e60-87b2-81e66866ac4c@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sheng, On 2018/11/23 20:11, Sheng Yong wrote: > Hi, Jaegeuk and Chao, > > On 2018/11/15 15:50, Jaegeuk Kim wrote: >> If namelen is corrupted to have very long value, fill_dentries can copy >> wrong memory area. >> > Is there any scenario that could hit this corruption? Or this is triggered I didn't see such issue in my test, I guess it may be caused by fuzzing test. Thanks, > by fuzzing injection? > > thanks, > Sheng Yong > >> Signed-off-by: Jaegeuk Kim >> --- >> fs/f2fs/dir.c | 12 +++++++++++- >> 1 file changed, 11 insertions(+), 1 deletion(-) >> >> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c >> index bacc667950b6..c0c845da12fa 100644 >> --- a/fs/f2fs/dir.c >> +++ b/fs/f2fs/dir.c >> @@ -808,6 +808,17 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, >> de_name.name = d->filename[bit_pos]; >> de_name.len = le16_to_cpu(de->name_len); >> >> + /* check memory boundary before moving forward */ >> + bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); >> + if (unlikely(bit_pos > d->max)) { >> + f2fs_msg(sbi->sb, KERN_WARNING, >> + "%s: corrupted namelen=%d, run fsck to fix.", >> + __func__, le16_to_cpu(de->name_len)); >> + set_sbi_flag(sbi, SBI_NEED_FSCK); >> + err = -EINVAL; >> + goto out; >> + } >> + >> if (f2fs_encrypted_inode(d->inode)) { >> int save_len = fstr->len; >> >> @@ -830,7 +841,6 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, >> if (readdir_ra) >> f2fs_ra_node_page(sbi, le32_to_cpu(de->ino)); >> >> - bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); >> ctx->pos = start_pos + bit_pos; >> } >> out: >> > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > >