Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7714334imu; Wed, 14 Nov 2018 23:53:49 -0800 (PST) X-Google-Smtp-Source: AJdET5d9aj7GtHIBP1B3PtTRq+2twatGUJrcPHcqh+hgkQ9ez5TOnHRNWH70OOYNR4BOijTTvuCS X-Received: by 2002:a17:902:8a89:: with SMTP id p9-v6mr5295485plo.183.1542268429171; Wed, 14 Nov 2018 23:53:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542268429; cv=none; d=google.com; s=arc-20160816; b=UY6X94kZUhceGB4yDP/n43xuMdkCXguf12ga1nCPkfpEbDqwyarg9z3hG6jZLHzEpF qgeYKQccpLO0TmeC7bR1+K2BCh67h4jiJnw48v5ytgWNaq4hjKjE6EUPk4MztOoI5KtS 8eFXihJ4FLPTTTF/ORHepuDi+IIqGZxICTegx9uvNR1aqGW8yQpinIOs/lT9w+zvDIsO fgLHFRDOD5ATlXQczF7Z7pCQpbQWZVYcMzParaUCUYFdcigCJK0qmE6mZdf1bC4ASPsV 66e6Xihht5hqyJech922cq/z9r2zz8Cqy1jOV4E91UkRVZ/spAoIoV9dFANQ0e+syFlE HrUQ== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/2XYqhT3sVPU73ntB5s47Y4xad6ulrCQpFFIcmfoMGw=; b=HWnzyXKHfzS0hbF8KF172fpXm591QCmhKsqTKVo98pLh1z0qas6ICJZjfCmjblPfFi BNkxCT5p3tCUpfXaGRtbZr1fIqHeii6EV+sLDUo1Fty3pGNzGSiXBGTD/TbAJi+7QJ1/ Z5rKZxRF7jwRLwLE7r7LzciGXK3xRV6G6RnsV+gnzMV3cJofGoebfndNv6bQyS9UxfqW bL/5inkf6XAj4+sTn3DvRS///059w5TbD1gE+xa1Kgbzr/pRRYr+5K6xox65V4PxgTpo 6l0FLGj3dtzlahKnPF8EkqBTigndpvj7aS5dka9UUFpoK5zqP07IQTdJQSUpKWHxlsy5 hCTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gTn9mHRw; 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 e32-v6si25341261pgl.129.2018.11.14.23.53.34; Wed, 14 Nov 2018 23:53:49 -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=gTn9mHRw; 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 S1728861AbeKOR5Y (ORCPT + 99 others); Thu, 15 Nov 2018 12:57:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:36590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeKOR5Y (ORCPT ); Thu, 15 Nov 2018 12:57:24 -0500 Received: from localhost (unknown [64.114.255.114]) (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 B998621582; Thu, 15 Nov 2018 07:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542268240; bh=dW5thBo9QZtFQDiLs1oyMwoVBSfecm34gHQIkSStpO4=; h=From:To:Cc:Subject:Date:From; b=gTn9mHRw0gRcY+dD/Cio28cBNZnu1PbKV0LAcPjVRm1sya10Fdndwi66E5KKj0CWS Gma5rzc55D2A5FsY92AcBQExvun6OblzOdJ9bEyVY3Bj8+YntURT0vSw69y5WW8/Gj gHFpNInbn21PKGlQDFbNc6udTbMiXpqN8QERpBAs= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH] f2fs: check memory boundary by insane namelen Date: Wed, 14 Nov 2018 23:50:40 -0800 Message-Id: <20181115075040.83500-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If namelen is corrupted to have very long value, fill_dentries can copy wrong memory area. 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: -- 2.19.0.605.g01d371f741-goog