Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp824298lqo; Fri, 17 May 2024 02:43:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTU4cGQOpoqDRs/Sx9wEvqIwSSMptY8HkvulTB0AU61/mfDAcnuiqNAxBrPrVqw8rXFVf88A3aSF/jNsWYwUgkPgA4aBL9JCKpCcDK8A== X-Google-Smtp-Source: AGHT+IHfw/LzuYKmY8m0mFsDc13r4l64F/yg0mmbycpWxIRfNdEGqKSrN21Qy3uuT0qoThALJqaw X-Received: by 2002:a17:902:7c89:b0:1ec:2517:3a06 with SMTP id d9443c01a7336-1ef43d2e938mr162078605ad.27.1715938996317; Fri, 17 May 2024 02:43:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715938996; cv=pass; d=google.com; s=arc-20160816; b=HrMdliE2PfwIr92jKXOoZ2GgewSKkQn2YxixbzDeCs/nZiX6DEOoRdRvz77V3JBoFD YiGjZ83VeUcFmciU4lm1n51mfQNsMMA5WUuEwvRuRKJKU7TJrUu32Jb5fVbWyNfsq9v0 lfr/zC9vd0WicC0tqobANYe+DGNSg89DQT1VSQSIzKceHZLA8H+P3CAFm4JeopWxsKHd eXRNdpozTWfVlbIed9AfX3+VuuOjAff0jHgRbzuWDTm4Xa0iRNw6JCER1RUhooOtx7XS v0lcSv0YdAE0f75RUAX0k8KsVEaKxBXRgxcUcvYBd0063bRd9bMerQHVfCXHz7+9deMy D8Nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=40GtNblDPP3TS7cSe7qZNOe3ShmaHLkVbPBVLZEn+n4=; fh=0G9Bu9/+gWj/4lmtoTNxOcMogOdFXL0UujPNAlTKDhA=; b=KxKT3kKKjdVWtqEXDeoJqbdroRcGb+h9f9YWL7ZvQKHq2S2H1783dn4CCDzzYIJfxL fAcUNI5CjpbtvfHPscXSjJDbSf08MtWAbaaI3FgKnsEPjnONMZn3lhpE6UH0SZjlMEkO oVtGjo3XaofUnk5BSJV3SME5nuQ8G0hOIeTVqD44ZPRvkFRM0fCoOruIKQfkcbnM2wvb Yb6CAk6IP0xk/mjMSyW+Roq7QLL95XGyYEKlUrf3JJ8rT6zOKBeyjoy5I+BN/dUKw6Qd p7lKStPKvoCD5Acov56T7IwlySJ3uxdyvUFOvcCqf12WA3cLSrR1iKN7f30uGhEyigUy NCnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=eZfbJz9C; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-181948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bad7ad2si165232735ad.152.2024.05.17.02.43.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 02:43:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=eZfbJz9C; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-181948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C6F07B220F0 for ; Fri, 17 May 2024 09:42:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 956B52421A; Fri, 17 May 2024 09:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="eZfbJz9C" Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 C32561FA5 for ; Fri, 17 May 2024 09:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715938931; cv=none; b=Xc90j4lUa63iYnZqqhkP+1FXxZ3WehCa2ALNnxrT1Vp30BfFkWynxBB+OOgrZVd4om2S7NpP22oBndhHuXCQvDM3+eeFKN09rHsqwnTc2EArKXUlObTbcjq2uptbXwmjPLZvWS1WWyul468MOjUDDGETrjG8fvWc+rvcTNFH7YI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715938931; c=relaxed/simple; bh=0nMX2E+j5B7we7+MGJ5BtRp3za/9P7lYO4LXsS704dc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mTFkXqQC3rhaeLrU/GLfaTvwUXMpLjV4Zg67eI8Z3ZcdFhDiTVIdrC/eHj2f5ZvhBG6hR13QuA7M7UZhzxPx+yxteuzMLi1z4ygDVgVmN2RfciWOc+6AgGh2eCwtGbjk3uphdlKAdvVgH1uyLcsvBRoezTRRyEn5frTpli+a71M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=eZfbJz9C; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715938926; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=40GtNblDPP3TS7cSe7qZNOe3ShmaHLkVbPBVLZEn+n4=; b=eZfbJz9CchVZn2yBcxd+T/t7s237ci1gF5/xCuprMkl7rE+3MPeA3F1S7ft/tuMW4JAQmcdgdLxnNU0lGKLEcFUjvy9zFlI9HhvRwlM6Ji162gxVbrx+oVeiKNQ1w2P/lnb3YxKlQxVhqJiwigKUiTgJND+Ai2+mcmkuuIUuhjg= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067110;MF=mengferry@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W6eF4Jj_1715938921; Received: from j66c13357.sqa.eu95.tbsite.net(mailfrom:mengferry@linux.alibaba.com fp:SMTPD_---0W6eF4Jj_1715938921) by smtp.aliyun-inc.com; Fri, 17 May 2024 17:42:05 +0800 From: Ferry Meng To: Mark Fasheh , Joel Becker , Joseph Qi , ocfs2-devel@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Ferry Meng Subject: [PATCH v2 1/2] ocfs2: add bounds checking to ocfs2_xattr_find_entry() Date: Fri, 17 May 2024 17:41:46 +0800 Message-Id: <20240517094147.87133-2-mengferry@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240517094147.87133-1-mengferry@linux.alibaba.com> References: <20240517094147.87133-1-mengferry@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a paranoia check to make sure it doesn't stray beyond valid memory region containing ocfs2 xattr entries when scanning for a match. It will prevent out-of-bound access in case of crafted images. Signed-off-by: Ferry Meng --- fs/ocfs2/xattr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 3b81213ed7b8..8aea94c90739 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -1062,7 +1062,7 @@ ssize_t ocfs2_listxattr(struct dentry *dentry, return i_ret + b_ret; } -static int ocfs2_xattr_find_entry(int name_index, +static int ocfs2_xattr_find_entry(struct inode *inode, int name_index, const char *name, struct ocfs2_xattr_search *xs) { @@ -1076,6 +1076,10 @@ static int ocfs2_xattr_find_entry(int name_index, name_len = strlen(name); entry = xs->here; for (i = 0; i < le16_to_cpu(xs->header->xh_count); i++) { + if ((void *)entry >= xs->end) { + ocfs2_error(inode->i_sb, "corrupted xattr entries"); + return -EFSCORRUPTED; + } cmp = name_index - ocfs2_xattr_get_type(entry); if (!cmp) cmp = name_len - entry->xe_name_len; @@ -1166,7 +1170,7 @@ static int ocfs2_xattr_ibody_get(struct inode *inode, xs->base = (void *)xs->header; xs->here = xs->header->xh_entries; - ret = ocfs2_xattr_find_entry(name_index, name, xs); + ret = ocfs2_xattr_find_entry(inode, name_index, name, xs); if (ret) return ret; size = le64_to_cpu(xs->here->xe_value_size); @@ -2698,7 +2702,7 @@ static int ocfs2_xattr_ibody_find(struct inode *inode, /* Find the named attribute. */ if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { - ret = ocfs2_xattr_find_entry(name_index, name, xs); + ret = ocfs2_xattr_find_entry(inode, name_index, name, xs); if (ret && ret != -ENODATA) return ret; xs->not_found = ret; @@ -2833,7 +2837,7 @@ static int ocfs2_xattr_block_find(struct inode *inode, xs->end = (void *)(blk_bh->b_data) + blk_bh->b_size; xs->here = xs->header->xh_entries; - ret = ocfs2_xattr_find_entry(name_index, name, xs); + ret = ocfs2_xattr_find_entry(inode, name_index, name, xs); } else ret = ocfs2_xattr_index_block_find(inode, blk_bh, name_index, -- 2.32.0.3.g01195cf9f