Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3718324rwl; Sun, 9 Apr 2023 23:10:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ZEFzSex4lpH4n5TMGRr9fPd8OmS24SFjZZrjIbiKRl2QlpWuF2BB6a2DoSN1ZlQFt32RPj X-Received: by 2002:a17:903:181:b0:19e:baa6:5860 with SMTP id z1-20020a170903018100b0019ebaa65860mr13403072plg.2.1681107014842; Sun, 09 Apr 2023 23:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681107014; cv=none; d=google.com; s=arc-20160816; b=cMPEFVoVejH8vmvz+VX6vF4FDnOgJGzWXUk/9R2N1qbMIYj4VgwuaLrCEWlxHKSnrU /kbrpGOzqYZ01xMrwNKsFaVrIFig373PlHsv41zrCFVnfDgZX7Vio4mmAirFsV8e57sf 4wNx8ic56to47/2x8tiTxLMwu4wzngExpjB0YWHzUEp6UHmiNqBACRiqZapa92P6TGfi khSModo5GKiS1hz7KY7dr18CxNMiEfKoi9VBTF+ycn90qGqvB92mCpZ46yOj+pvdsL/K CpnnpkNmW3tPnicz4mMdS/hAYLB8ZaJ725slCt6ziEvvGd15RNDyjrfcIu9JJOl4a2qP B9TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=GIt49rnRxUIpeHYbJvPIWM35MW4Y93Oyfe2DKuQ71Ik=; b=msK+PkuFGWtGZzBfOe3jWAmIDwNCNflFVnnJnJOEjaNc1DRaw1pG7FeuGQNbxe9Wz9 fmYUuDhqGCi2/YCwcPLq5K4ErjzY1SmihLvjkVWFe20tell2ALLUZ1LIp7V49HseAKyk 30gcjFkujxXW1GRo0FTO/7pg9KnYqdTysWjm8yQ9iag0o7wgwSaKwhnU85HPHhHHPuGL gT6Mx62DqLyVv536gdXyji5W2D30h3ZQZw8MtH2bVlSBW0PvvtQhs+bYV87RmwQAvms0 wr+gSHJbd24AMBoy7TJuvJ5Y4HTGYxEP51tNCfkqJGsTO5FWTmiA2pRMFlkM/MKLaxLn TRMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a17090332ca00b001a63d8efabasi2024946plr.445.2023.04.09.23.10.02; Sun, 09 Apr 2023 23:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjDJFyE (ORCPT + 99 others); Mon, 10 Apr 2023 01:54:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjDJFyD (ORCPT ); Mon, 10 Apr 2023 01:54:03 -0400 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A784B2D58 for ; Sun, 9 Apr 2023 22:54:01 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R811e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VfgWm51_1681106037; Received: from 30.97.49.25(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VfgWm51_1681106037) by smtp.aliyun-inc.com; Mon, 10 Apr 2023 13:53:58 +0800 Message-ID: Date: Mon, 10 Apr 2023 13:53:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH 6/7] erofs: handle long xattr name prefixes properly To: Jingbo Xu Cc: linux-kernel@vger.kernel.org, Gao Xiang , Chao Yu , Yue Hu , linux-erofs mailing list References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> <20230407141710.113882-7-jefflexu@linux.alibaba.com> From: Gao Xiang In-Reply-To: <20230407141710.113882-7-jefflexu@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/4/7 22:17, Jingbo Xu wrote: > Make .{list,get}xattr routines adapted to long xattr name prefixes. > When the bit 7 of erofs_xattr_entry.e_name_index is set, it indicates > that it refers to a long xattr name prefix. > > Signed-off-by: Jingbo Xu > --- > fs/erofs/xattr.c | 60 +++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 52 insertions(+), 8 deletions(-) > > diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c > index 684571e83a2c..8d81593655e8 100644 > --- a/fs/erofs/xattr.c > +++ b/fs/erofs/xattr.c > @@ -301,11 +301,39 @@ struct getxattr_iter { > struct qstr name; > }; > > +static int erofs_xattr_long_entrymatch(struct getxattr_iter *it, > + struct erofs_xattr_entry *entry) > +{ > + struct erofs_sb_info *sbi = EROFS_SB(it->it.sb); > + u8 idx = entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK; > + struct erofs_xattr_prefix_item *pf; > + > + if (idx >= sbi->xattr_prefix_count) > + return -ENOATTR; > + > + pf = &sbi->xattr_prefixes[idx]; struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + idx; if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) return -ENOATTR; ? > + if (it->index != pf->prefix->base_index) > + return -ENOATTR; > + > + if (strncmp(it->name.name, pf->prefix->infix, pf->infix_len)) > + return -ENOATTR; > + > + it->name.name += pf->infix_len; > + it->name.len -= pf->infix_len; > + if (it->name.len != entry->e_name_len) > + return -ENOATTR; > + return 0; > +} > + > static int xattr_entrymatch(struct xattr_iter *_it, > struct erofs_xattr_entry *entry) > { > struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); > > + /* should also match the infix for long name prefixes */ > + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) > + return erofs_xattr_long_entrymatch(it, entry); > + > return (it->index != entry->e_name_index || > it->name.len != entry->e_name_len) ? -ENOATTR : 0; > } > @@ -487,12 +515,26 @@ static int xattr_entrylist(struct xattr_iter *_it, > { > struct listxattr_iter *it = > container_of(_it, struct listxattr_iter, it); > - unsigned int prefix_len; > - const char *prefix; > - > - const struct xattr_handler *h = > - erofs_xattr_handler(entry->e_name_index); > + unsigned int base_index = entry->e_name_index; > + unsigned int prefix_len, infix_len = 0; > + const char *prefix, *infix = NULL; > + const struct xattr_handler *h; > + > + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) { > + struct erofs_sb_info *sbi = EROFS_SB(_it->sb); > + u8 idx = entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK; > + struct erofs_xattr_prefix_item *pf; > + > + if (idx >= sbi->xattr_prefix_count) > + return 1; > + > + pf = &sbi->xattr_prefixes[idx]; struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + idx; if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) return 1; ? Otherwise it looks good to me, Reviewed-by: Gao Xiang Thanks, Gao Xiang > + infix = pf->prefix->infix; > + infix_len = pf->infix_len; > + base_index = pf->prefix->base_index; > + } > > + h = erofs_xattr_handler(base_index); > if (!h || (h->list && !h->list(it->dentry))) > return 1; > > @@ -500,16 +542,18 @@ static int xattr_entrylist(struct xattr_iter *_it, > prefix_len = strlen(prefix); > > if (!it->buffer) { > - it->buffer_ofs += prefix_len + entry->e_name_len + 1; > + it->buffer_ofs += prefix_len + infix_len + > + entry->e_name_len + 1; > return 1; > } > > - if (it->buffer_ofs + prefix_len > + if (it->buffer_ofs + prefix_len + infix_len + > + entry->e_name_len + 1 > it->buffer_size) > return -ERANGE; > > memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len); > - it->buffer_ofs += prefix_len; > + memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len); > + it->buffer_ofs += prefix_len + infix_len; > return 0; > } >