Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1339157imm; Thu, 23 Aug 2018 01:06:08 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbmi6hVsbhnBq/0e65YfJAs1S6r3Ie1x3B97sFdw0zYFcbD2QsD+q7JOMVvVL3n6Q0hCsr0 X-Received: by 2002:a62:f0d:: with SMTP id x13-v6mr4262805pfi.221.1535011568138; Thu, 23 Aug 2018 01:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535011568; cv=none; d=google.com; s=arc-20160816; b=QC2BgCJuXCaDWzN0lRunet77l48dGBb3yX1J4JhASBq+8Sat5fEO9KhF28JoTgTsFS jU+YNEGbN+jzjTr2dhzgQ84sdUzASB5kXQErabC5eihZLkFxrGMkscOuYMDX+WCHP4yG vflQaTBAAVCYDKjy0sm7dVc/LpXzsElswOupd8cRdn2g4g+tgagg78Mu99SLQzrFd/39 kbjHfl8+7gtBUw3C5TvmazWOCc7Xr9hdmGrHK9eKM5ZYq6nEExhKFYfiWFOuDn62tpRl nEXcFqlTOPFzxV+CjTIsuy//na0TDoM3yq+oJTpd3dQ/jICh4K6AsxzYOW3tYSIyYsQh UVuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ybNj90LkWyX3PdDc9VakfvVgnjJ0RGLEkdfsoxRJ7Wg=; b=UiuLzObkRtEc4t53KrxpzyuM9fBzeVdIc2XF3Ld6Tp0K2vHgh2IXsqhgXLkfHYVwZC HY4j7puHdwRyS/yfJm3btLqitE7XxN+QTEIeRSVqGORgFVtwZFqB4zndAZsP5LZZZq3W BgBTRY7h/QPh6V1XlG1j1SBl8wVVRgkC6A/+/groYV3MHvrBFELzinHniYmJLN2FyOgk 46tA0fNv/MwU+VTj9Da7ktpe2HwWZbeYzzgN0Ug8VgAG7PbnAHKtta24SVkKKIjSdxOn IKoNQ9UzSQKznB+nvLoJfp+79crMLxY0OiMRJw/taCFqASR9DpaFmnYqJgyQ9T9b2PiR wiHw== 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 t2-v6si3928480pgg.422.2018.08.23.01.05.52; Thu, 23 Aug 2018 01:06:08 -0700 (PDT) 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 S1728818AbeHWL30 (ORCPT + 99 others); Thu, 23 Aug 2018 07:29:26 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44308 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728796AbeHWL3Z (ORCPT ); Thu, 23 Aug 2018 07:29:25 -0400 Received: from localhost (5355525A.cm-6-6b.dynamic.ziggo.nl [83.85.82.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 85F37C18; Thu, 23 Aug 2018 08:00:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Jeff Mahoney , Eric Biggers , Al Viro , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 79/79] reiserfs: fix broken xattr handling (heap corruption, bad retval) Date: Thu, 23 Aug 2018 09:53:55 +0200 Message-Id: <20180823074924.369245762@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180823074918.641878835@linuxfoundation.org> References: <20180823074918.641878835@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit a13f085d111e90469faf2d9965eb39b11c114d7e upstream. This fixes the following issues: - When a buffer size is supplied to reiserfs_listxattr() such that each individual name fits, but the concatenation of all names doesn't fit, reiserfs_listxattr() overflows the supplied buffer. This leads to a kernel heap overflow (verified using KASAN) followed by an out-of-bounds usercopy and is therefore a security bug. - When a buffer size is supplied to reiserfs_listxattr() such that a name doesn't fit, -ERANGE should be returned. But reiserfs instead just truncates the list of names; I have verified that if the only xattr on a file has a longer name than the supplied buffer length, listxattr() incorrectly returns zero. With my patch applied, -ERANGE is returned in both cases and the memory corruption doesn't happen anymore. Credit for making me clean this code up a bit goes to Al Viro, who pointed out that the ->actor calling convention is suboptimal and should be changed. Link: http://lkml.kernel.org/r/20180802151539.5373-1-jannh@google.com Fixes: 48b32a3553a5 ("reiserfs: use generic xattr handlers") Signed-off-by: Jann Horn Acked-by: Jeff Mahoney Cc: Eric Biggers Cc: Al Viro Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/reiserfs/xattr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/reiserfs/xattr.c +++ b/fs/reiserfs/xattr.c @@ -791,8 +791,10 @@ static int listxattr_filler(struct dir_c size = handler->list(handler, b->dentry, b->buf + b->pos, b->size, name, namelen); - if (size > b->size) + if (b->pos + size > b->size) { + b->pos = -ERANGE; return -ERANGE; + } } else { size = handler->list(handler, b->dentry, NULL, 0, name, namelen);