Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3505394imu; Mon, 7 Jan 2019 04:44:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN7rgGqzSUAfZRQx0ClLwLn+6tz5hsixrABhf2rO2FeE39q3NUAuHiMCtg9rCGfVCs4FE/Lb X-Received: by 2002:a65:4381:: with SMTP id m1mr10597320pgp.358.1546865080037; Mon, 07 Jan 2019 04:44:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546865080; cv=none; d=google.com; s=arc-20160816; b=ItZ5wctM/5RzNtwxcPuTXgNJVbI4B/YZxF/2jOL92fYXMdopPxYHnMaywp36b2d6XH NlyTXp9aG20/36SwrcCQG+rO1jWqnqTfDmiEGUf87ZyK8RbawTL/VlxTtgPWJnoLq+st k+7AOYPEaPmFYJ1uTShT2c9RAhT9uN+s4ua9tOA/jM7/wv860iX6fU7vX5sJkZ2KjGLM +X/+gomBNptVImn5/gZu8AG2QavJn0OsztX2mhFiiZldBgDdUJkKegcXfYzabMdNI1pT DR1ieDUkNt+JFoY802/VT8KIGzseXotl5GABE7rVvHlKFkT7HDkVsR4ASTCOephVzIO6 QBwQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ijqd27QMbwaeXaAPgfcvoWZ3J9qTwy3vMHoLADIqL5w=; b=wm1kK3Uz1UbBVwRn8H65DsaCaY1mJ8no8B+N4UD5lx3bfPaDDUKt6ySXt7DDt3e7NR yGrFodG7XUxUPqxGGMM1qWqLO2SVBgmTxrwyZF+JwXaisa+B5JkKIP/5fztDp2/whHpX 4efBzgnRvO7BQOBMQHzntEh45nq1nHuP82vyp8uCRCBo9I5wg733SVcmpmr/89g7EKdw 22CLsA/V42xt83fsp47ZDdyjO29J2kLycutkp+naFrNTHKJAZmYy2psMjwxXjD4glsmF 6k4OwqcIv/U1fdRGHUg7El7T1D3KzVqmXz0+lmNGODMYFSyWHvx7SdJc2hlfIqn2WfXu F8lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GZf6+bp5; 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 n24si16928530pgv.119.2019.01.07.04.44.24; Mon, 07 Jan 2019 04:44: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=GZf6+bp5; 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 S1727735AbfAGMmm (ORCPT + 99 others); Mon, 7 Jan 2019 07:42:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:58404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727461AbfAGMmj (ORCPT ); Mon, 7 Jan 2019 07:42:39 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 134BD20449; Mon, 7 Jan 2019 12:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546864959; bh=bPhC9xg5l96XF0a00geWPw6p5VKPJkKSoOeiiHRbN+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZf6+bp5KEhLoyOcx1SEtLuOF2Eh4Xg90XIadsqn0Q6YsH8FufoOksJNgGod7NBaY kLbANpYcO7F3D9At3aPpIGtFkb0I5/cuifBsZZELL3eCj9py3OwNs/SYLjU4J5ARNj 1jOWJZ3+nqX/tGapdkWg4YyZHgpMbURki3j9T0QE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jaegeuk Kim Subject: [PATCH 4.20 108/145] f2fs: sanity check of xattr entry size Date: Mon, 7 Jan 2019 13:32:25 +0100 Message-Id: <20190107104451.352529485@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jaegeuk Kim commit 64beba0558fce7b59e9a8a7afd77290e82a22163 upstream. There is a security report where f2fs_getxattr() has a hole to expose wrong memory region when the image is malformed like this. f2fs_getxattr: entry->e_name_len: 4, size: 12288, buffer_size: 16384, len: 4 Cc: Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/xattr.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -288,7 +288,7 @@ static int read_xattr_block(struct inode static int lookup_all_xattrs(struct inode *inode, struct page *ipage, unsigned int index, unsigned int len, const char *name, struct f2fs_xattr_entry **xe, - void **base_addr) + void **base_addr, int *base_size) { void *cur_addr, *txattr_addr, *last_addr = NULL; nid_t xnid = F2FS_I(inode)->i_xattr_nid; @@ -299,8 +299,8 @@ static int lookup_all_xattrs(struct inod if (!size && !inline_size) return -ENODATA; - txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), - inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS); + *base_size = inline_size + size + XATTR_PADDING_SIZE; + txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), *base_size, GFP_NOFS); if (!txattr_addr) return -ENOMEM; @@ -312,8 +312,10 @@ static int lookup_all_xattrs(struct inod *xe = __find_inline_xattr(inode, txattr_addr, &last_addr, index, len, name); - if (*xe) + if (*xe) { + *base_size = inline_size; goto check; + } } /* read from xattr node block */ @@ -474,6 +476,7 @@ int f2fs_getxattr(struct inode *inode, i int error = 0; unsigned int size, len; void *base_addr = NULL; + int base_size; if (name == NULL) return -EINVAL; @@ -484,7 +487,7 @@ int f2fs_getxattr(struct inode *inode, i down_read(&F2FS_I(inode)->i_xattr_sem); error = lookup_all_xattrs(inode, ipage, index, len, name, - &entry, &base_addr); + &entry, &base_addr, &base_size); up_read(&F2FS_I(inode)->i_xattr_sem); if (error) return error; @@ -498,6 +501,11 @@ int f2fs_getxattr(struct inode *inode, i if (buffer) { char *pval = entry->e_name + entry->e_name_len; + + if (base_size - (pval - (char *)base_addr) < size) { + error = -ERANGE; + goto out; + } memcpy(buffer, pval, size); } error = size;