From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E1051DF257; Wed, 6 Nov 2024 12:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730894860; cv=none; b=E/axKoF7ECQUcms4YrLg3iiz+26wNZu4SQ8XG0fJ5B/Y7OMYL0qBLEfUmernCzUVD2tjYBwk2oI0eNRhnGRyL0BJ1Uh5pzAf0Z/COtddkqGvMGvEgUgMSKZyR8cnyR4JRX0wZsqgqZAjJxaMSkZaDFLP4WXUd/kt/XgSQLQkPKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730894860; c=relaxed/simple; bh=bZuLPjgXXn1S5PUo2SXTan5j0vRlSTcj+jO8hGvR6Cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PwKdGvds550rg51NFIkYvc7WXt0vEE8f7GO8GKs9IJrime4r5Oa056fVLSNVrCltx3kRS/EOmGx/zqZ9WruFlybChWufXSzqTLe2zUZ0W/l2yceEKX8r4xI4aH3WB0p+aKNxETRN0Bc7O/qPq1jNwNZvxAzzIFYDgz6dEEitiqk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oXoRkAFG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oXoRkAFG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB276C4CECD; Wed, 6 Nov 2024 12:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730894860; bh=bZuLPjgXXn1S5PUo2SXTan5j0vRlSTcj+jO8hGvR6Cw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXoRkAFGbugprZoPYzdVP9y5e7LIQ2IZlO1Q43BfxLlkAVxfG/3ycQVWVtLYWl64U Akrx6iveU2ZwrWpWXxiSLbwVVDTQ0a1gJwROG6yDQKc3IO60GdLfCmLpRlI3yyJQhs rI2NDTn1Br0tDW6ZN6LvMw4hprZ/eMQ2OkyU8lfM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ferry Meng , Joseph Qi , lei lu , Changwei Ge , Gang He , Joel Becker , Jun Piao , Junxiao Bi , Mark Fasheh , Andrew Morton , Sasha Levin Subject: [PATCH 4.19 025/350] ocfs2: strict bound check before memcmp in ocfs2_xattr_find_entry() Date: Wed, 6 Nov 2024 12:59:13 +0100 Message-ID: <20241106120321.499530892@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120320.865793091@linuxfoundation.org> References: <20241106120320.865793091@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ferry Meng [ Upstream commit af77c4fc1871847b528d58b7fdafb4aa1f6a9262 ] xattr in ocfs2 maybe 'non-indexed', which saved with additional space requested. It's better to check if the memory is out of bound before memcmp, although this possibility mainly comes from crafted poisonous images. Link: https://lkml.kernel.org/r/20240520024024.1976129-2-joseph.qi@linux.alibaba.com Signed-off-by: Ferry Meng Signed-off-by: Joseph Qi Reported-by: lei lu Reviewed-by: Joseph Qi Cc: Changwei Ge Cc: Gang He Cc: Joel Becker Cc: Jun Piao Cc: Junxiao Bi Cc: Mark Fasheh Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/ocfs2/xattr.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 8ec85c2503f23..bf00c7d4282b2 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -1082,7 +1082,7 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index, { struct ocfs2_xattr_entry *entry; size_t name_len; - int i, cmp = 1; + int i, name_offset, cmp = 1; if (name == NULL) return -EINVAL; @@ -1097,10 +1097,15 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index, cmp = name_index - ocfs2_xattr_get_type(entry); if (!cmp) cmp = name_len - entry->xe_name_len; - if (!cmp) - cmp = memcmp(name, (xs->base + - le16_to_cpu(entry->xe_name_offset)), - name_len); + if (!cmp) { + name_offset = le16_to_cpu(entry->xe_name_offset); + if ((xs->base + name_offset + name_len) > xs->end) { + ocfs2_error(inode->i_sb, + "corrupted xattr entries"); + return -EFSCORRUPTED; + } + cmp = memcmp(name, (xs->base + name_offset), name_len); + } if (cmp == 0) break; entry += 1; -- 2.43.0