Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp5028lqo; Wed, 15 May 2024 18:25:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuTkVW1B6OriDlUpdFnUewE9hwRyioHPX/HxLSL+5Hruy3hejrO5ctSNX0wVSMZKLcxUhCNgTWGF8MpJOabsP+lqx9fUJRAiJmwMBIJQ== X-Google-Smtp-Source: AGHT+IHi9owL4A1YDXOTya/F+i/izaJfcRc5hQw37MqyeAReokTL3eI+WjJuthHUX0rk8S2K/lMz X-Received: by 2002:a05:622a:12:b0:43b:d8d:30f with SMTP id d75a77b69052e-43dfdaa9e5cmr213778511cf.2.1715822743595; Wed, 15 May 2024 18:25:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715822743; cv=pass; d=google.com; s=arc-20160816; b=QsPZ/nR3GUwsQpwxfIqfr1kK30v8BQyj0VbrqoDO0V8F8p/CIwCC4TcCkYOSjg+9EA kf1nN5bAKyPHH/tRmtW0/unsC+ym+TG0SBWEStvifJWknAMnS4mmMUirQwjkiiN1GQUw DZg3RxOxkdgkIM3vl7t0euDQqjC/WH3yodDGm+mNw7XUj3+nXyrOY6+MnxixG+O+CgAj 8WsjmTuGJS+OJfbSz5QlQB6MY8kWk3qRg/KhAz5FAHRDOIhY6EmsFCcAeOwBBzZ0Akig Ec1ybwqdurhAUU55njHmS9YpLxQ42R8QX/mIwT+dBexRF9AN6iGLq+iTfi9U5JoLxVu4 VwoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=r1isWmBJiUBnwSRE2U9rv0XS6h/F0ZDmTQNKcWxVn5Q=; fh=WfhFQgsjgKYWVrDBEYDEMC0ngMsiwIjMBWMv4Kg1U9w=; b=H0bx0F1/3mDT5ezm36DeJ5J/6sABT66SvgAYBgHKLYi25gvwZ7u8I2Fuasb83ki/Qg k0s+VL90ines3+O9HzzGONcJj3yYAxkx/QnGCvjRlWEv9FTaJFpVdudvHZ/+/joDxuEq yilCiSjzr0Y95rbSrJ1YLQSF34m2EskwmQirdaUq3KEReV5yDz9+fHVTN27zLrjG5VXg HZN7yKfxOcN1vNxWjNcxkQjUDyhBCBvmV06YBqx76rfcVOLwO3/VWF0xey9mGcwP36fz HIALIlxuJFwzF+Hj/MKmxVWtJVyfvdW8ft9LC5D3kKbwbQirS/AkJA1MZ99lp16HO2MX nfmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=sYZroa7X; 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-180546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180546-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43e2ccc15a2si41081261cf.624.2024.05.15.18.25.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 18:25:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=sYZroa7X; 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-180546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180546-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 548931C20DE5 for ; Thu, 16 May 2024 01:25:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E5D1137E; Thu, 16 May 2024 01:25:41 +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="sYZroa7X" 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 6890610F1 for ; Thu, 16 May 2024 01:25:36 +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=1715822740; cv=none; b=aO2tGN+TS2EPlZfRMyZIblfeSpPpoRd+zAMvDkI3kLLtjxlYuKiQumc1Fvqq+IRSy0lV6biTMQJOnVP7eA06tHpwZtgcWeuWrUmmc+ymwNWGmtlvshKEbqpu1JF+8RpYDZs25IOwbOcjV67VYiK240A0kUzyAyFp+ZX1m/lVEc8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715822740; c=relaxed/simple; bh=hzGJgKulpQX2J2VYQHpmUzBVbITwBgGfAjtKWVSlGtc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VGFkMuqHYO2ti6wLngShmE6XswHr4X+9ISnxTG2aHjj9KRYjOnqQCsOlW7F2zcV4hhKM07ri4/rrmn1so+PJbbSy1IWq5s1RmScafUIckjc95EwWcIX+PlNOa23YGzO5gpgJpn6eYWIPjnGqx2UdsHGqcTY0ieUXat1J6AL3t0I= 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=sYZroa7X; 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=1715822728; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=r1isWmBJiUBnwSRE2U9rv0XS6h/F0ZDmTQNKcWxVn5Q=; b=sYZroa7XpUiq6yshDlolEvEle0qYc+iNHeyzHyXt8MPbSlBVY73Ujw6MHLwYhjhqflHooT7fHTqk3zb5+Xyc5lPGKnRaTnwizuYZDZg54J7QhqL+Kchvf/VrPcdVlzN8IGAvwkdOoRR+NRFNbW1XhsFUYEiuSAFSdDtwYvMEpVU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R411e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0W6ZBgVk_1715822726; Received: from 30.221.128.154(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0W6ZBgVk_1715822726) by smtp.aliyun-inc.com; Thu, 16 May 2024 09:25:28 +0800 Message-ID: Date: Thu, 16 May 2024 09:25:26 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] ocfs2: add bounds checking to ocfs2_xattr_find_entry() To: Ferry Meng , Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev Cc: linux-kernel@vger.kernel.org References: <20240515132934.69511-1-mengferry@linux.alibaba.com> <20240515132934.69511-2-mengferry@linux.alibaba.com> Content-Language: en-US From: Joseph Qi In-Reply-To: <20240515132934.69511-2-mengferry@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/15/24 9:29 PM, Ferry Meng wrote: > 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. > I'd rather restructure the commit message as below: 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 | 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, 'end' can be obtained from ocfs2_xattr_search directly. Thanks, Joseph > + 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,