Received: by 2002:a05:7208:13c3:b0:82:bbfa:f723 with SMTP id r3csp1543964rbe; Wed, 15 May 2024 06:32:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5XjGFAf1ROLM8nuTZ15Ci1XPBMt3JvY0TxdTAOIOKMEKNIc3/Sn7flzhHNrKvyXMHC4RQqGAXugYxe4Kwv+P4nEi+NLjKpjl7sxMpsw== X-Google-Smtp-Source: AGHT+IExTZii756FGZfpg9ToO2kYkZIh2xmYdiCf4fe/Ei4/3NR4AYf3NuZhNY1FD/aLP7jo5n8Z X-Received: by 2002:a05:6a21:2727:b0:1a3:e2c4:956e with SMTP id adf61e73a8af0-1afde0d54e0mr15708125637.25.1715779928299; Wed, 15 May 2024 06:32:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715779928; cv=pass; d=google.com; s=arc-20160816; b=P87Hw9hczZT1AXvILckY2j51SM0NQBcQbd99jkgPN2CBSncugQjCUrJ/dEDjX6ApKB dBTszVTu545BXRP79czuefnLPTdzXSp/8NV2Za7lvP62rnaye6A//b4XTUR2WebugLX2 d67Gy3SIrRujFsc9L0YE64YELg6+Ndsbe9qYSvUOCuCGU9/4RaW+SWuqhExC/MTQRO6R JZGmSmM214i/Ok0yd1acz6QHDKuifnD4ESIvr7pjpcRHocmAmdOt9hpFNl8gikXrxULW oA+Wugt7tl7GkA+NC2FMvxr7t6SvmEvlwQjf9lhT3zkDJjw29OwcjQvDAsu3O2NKcNI1 SXPA== 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=51HpooU0DkeKvMgR87mxZX64g8YR7tYzfAIqWRzGG0o=; fh=0G9Bu9/+gWj/4lmtoTNxOcMogOdFXL0UujPNAlTKDhA=; b=AEiAfr3c6e7DpncVqd0TPqyyU3rrQNSEV+0ZNUit0nktlT0QjeKOFPpI7yytlGHC6z aqnKLNnRoYeW8lPZyEcw/0npGHJ3bk9s4FTv9MfL2LY2AJMnpIDlZVZJ8dFxsqLf3F+u TGQvuhTLW4MAmiaQ61559qppZBMvI69n6S7VYiooj1c7iL+B3MHa5hY0ixH1BvJWFTSB ityWSgSfn0c6zwQ1K9QearLe4u+OUNZPKXjAWGnyxTwDV8DWcpoKYrxBfE7D+I6hKFwy P6hnH8YbaV4EpKS1MJLn+O36izP9Dqouypg+rCwiUIwrUh1aVMtOPV/8izWs9Y3OsQOS cBPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=j3qSWeB1; 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-179916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179916-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 sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4fa8f040asi7850218b3a.118.2024.05.15.06.32.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 06:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=j3qSWeB1; 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-179916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179916-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9539F283630 for ; Wed, 15 May 2024 13:30:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94BBE8595F; Wed, 15 May 2024 13:29:59 +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="j3qSWeB1" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 0D9B985C4E for ; Wed, 15 May 2024 13:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715779798; cv=none; b=WlKSlxCcwzq6b6ao9XqO/c5RaVUeCloZok5Kt+GIVMQ+GRCpFecUGdyKF8EYX2FXcl6YnWUE5t/FMa1uejHCkEqYg5nspA53ngVa2a5eHONADGWsvF/6MQQjtDBZ+EJkpgFvph3s5CZ2843fHMoGgaktymqB/x+WhdHbRxNhxBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715779798; c=relaxed/simple; bh=gz0ggfN6+8zfLHC6A1tTQMN9AyVLIKPJ0bhOy7smPrU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c4k7us4fA1LtbZAesNLlohNaXWnB9NcgnrbrFnLyXZr/i3VI/VJHuAGldjDUZdX2YdMDlw0lcMSbp4mqz2kYfCERzkmhUUrp6Wi0fYWvozWfkcwMGMRaeLQ40D5M7LcKaP8T1/4bewY6CBHnErCSnstcmdChCtWgZC5Y9nuWelQ= 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=j3qSWeB1; arc=none smtp.client-ip=115.124.30.97 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=1715779789; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=51HpooU0DkeKvMgR87mxZX64g8YR7tYzfAIqWRzGG0o=; b=j3qSWeB1b7PgB787B5JiLrjNs3fM1W7ImvnYRJu4tgjdUx8vuwhgdmct/HXES6CHibs4ZV2q3RLRYuKM3qOs/fhj623Xj4FTJKPgnILZA52HGt/gWtCcz2GDMFYnrJ7+Q0t1c0aOdTMxTSsuKLPRI6hsAc8zg1GnL5q1gglvJKQ= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R381e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067111;MF=mengferry@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W6YDIFU_1715779785; Received: from j66c13357.sqa.eu95.tbsite.net(mailfrom:mengferry@linux.alibaba.com fp:SMTPD_---0W6YDIFU_1715779785) by smtp.aliyun-inc.com; Wed, 15 May 2024 21:29:48 +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 1/2] ocfs2: add bounds checking to ocfs2_xattr_find_entry() Date: Wed, 15 May 2024 21:29:33 +0800 Message-Id: <20240515132934.69511-2-mengferry@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240515132934.69511-1-mengferry@linux.alibaba.com> References: <20240515132934.69511-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 Just add redundant (perhaps paranoia) checks to make sure it doesn't stray beyond valid meory region of ocfs2 xattr entry array during a single match. Maybe this patch can prevent some crash caused by crafted poison images. Signed-off-by: Ferry Meng --- fs/ocfs2/xattr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 3b81213ed7b8..37be4a286faf 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -1062,8 +1062,8 @@ ssize_t ocfs2_listxattr(struct dentry *dentry, return i_ret + b_ret; } -static int ocfs2_xattr_find_entry(int name_index, - const char *name, +static int ocfs2_xattr_find_entry(struct inode *inode, void *end, + int name_index, const char *name, struct ocfs2_xattr_search *xs) { struct ocfs2_xattr_entry *entry; @@ -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 >= 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, xs->end, 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, xs->end, 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, xs->end, name_index, name, xs); } else ret = ocfs2_xattr_index_block_find(inode, blk_bh, name_index, -- 2.32.0.3.g01195cf9f