Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp589742imu; Mon, 26 Nov 2018 15:26:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/VPX6LXmaEssjmwI11mLM0s/1s3UDCl92KsF59K412ktg+JRTNo/nxAJUPX4kgQF3AV2dq7 X-Received: by 2002:a17:902:380c:: with SMTP id l12mr29274490plc.326.1543274800641; Mon, 26 Nov 2018 15:26:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543274800; cv=none; d=google.com; s=arc-20160816; b=FSEHE1PJeRKvgH8rw/ANQLPDa662ULIZDQ/Y6PvedtEO0qd+1BHNY7oVo/7aPeWeot bUwN6/EntGaOFIaW6R6Kqrk8TOlOHGUz/Y2CHHjEwsthtU78aafksTUubnMawzBcJHQp EwhxtFb7QGdMEVVNBE6JH73SFuALQAnDuFxPiVbpn9YtT9Q3/syOXg8K1Wv4wCc+B/E1 pyiKtEEHwWC2cq/2B+ouxpdUywUJd64ECivT7mIbI9D+2qOLkSR5x4qME74njWHPktYS TraJC/ao0zVbsNTnCTxlQYpguYeQbAGefzVrLendwrfRiDNPw2n5ee03slWvLY9MWaAn nN7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=C83Y9CnIXzcrX316bgcg0RUDek4RaC+2++Ca3IZ5nkY=; b=DdwTXFU30EsK8iQh76e56kmTBgBUD3UkqYgfZ0C0hWY2CTJhS1Y2y60AkYAO8qYF8t NS99Vy5jwFcl++tMvEOmTzuqmPVRKCKure+klLENcD3g5WANS97azhzjcZJRSPE6RH3J hYNTS5z3nScFHIOzxkODio3APwdRmxkcebffipO+GqOGy2KcaBQtySyzEsmL3uWPG06L nWoSYvHBPtvHHhKgkQ9zbpiWxtnYf7WBUdBiRHMlBf5qKABUM0FQsIaNvzKfBOK9vwQb oDda9ad3hrSPqiz9UYcuy2F+G6Vul4Ipl8C3e4ikTrjuANZjZisbVKTGwipFdTvFsj20 IaRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gCMr4esE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si1751084plt.5.2018.11.26.15.26.25; Mon, 26 Nov 2018 15:26:40 -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; dkim=pass header.i=@kernel.org header.s=default header.b=gCMr4esE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727599AbeK0KVR (ORCPT + 99 others); Tue, 27 Nov 2018 05:21:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:48906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbeK0KVR (ORCPT ); Tue, 27 Nov 2018 05:21:17 -0500 Received: from localhost (unknown [104.132.1.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B35F2208E4; Mon, 26 Nov 2018 23:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543274730; bh=PF7iB6C2AhXKF3kqUaQXYATUPxfZ3B0YbXdWF+vWhwI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gCMr4esE3ob7kG+XTxtzfP4BNWbUsJmnNuJFybjvyk9YwK6CSXxodlhVa+OuBNCTL 3Fhqor8TBrQYhUi9wQey0SrwAWe2rlg6eOcw+tLza1bbItiFE5FkfSMrsKom23jCZK aRcVHq5GE2dmtfMYrFmfRbgGekL9piwbQE0LkBzk= Date: Mon, 26 Nov 2018 15:25:29 -0800 From: Jaegeuk Kim To: Sheng Yong Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, "gongchen (E)" Subject: Re: [f2fs-dev] [PATCH] f2fs: check memory boundary by insane namelen Message-ID: <20181126232529.GC55960@jaegeuk-macbookpro.roam.corp.google.com> References: <20181115075040.83500-1-jaegeuk@kernel.org> <3d213d40-a4b0-6e60-87b2-81e66866ac4c@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3d213d40-a4b0-6e60-87b2-81e66866ac4c@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/23, 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 > by fuzzing injection? Hi Sheng, It's from a fuzzing test. Thanks, > > 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: > >