Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3744582rwl; Sun, 9 Apr 2023 23:44:32 -0700 (PDT) X-Google-Smtp-Source: AKy350aS8E+0i5cougJhf2Li+wBhSbb/ehDsM2SbPHRe0KMgk2ieAX1C29SGajkH8YxtJoQKbKWu X-Received: by 2002:a17:907:25c8:b0:933:4d47:55b7 with SMTP id ae8-20020a17090725c800b009334d4755b7mr7775148ejc.2.1681109072729; Sun, 09 Apr 2023 23:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681109072; cv=none; d=google.com; s=arc-20160816; b=ffqJ8I+yWqgtkVTZFpSLCPYnbUyhqgKUc1Li2nqeLJOZiJUZTQ0WLVuhTUQPVa6142 T2fppGsx+X8YwLu4BEyRxJxizJE/fA+veMIZgc5V29so/kd3VWlibAGb6xRAvovRTl8/ xAln2SyTewtuSmzG77/UJhU+EPklk8XNCKFobr2HlOA6PcGpWaLoS0GtLyuO2zbIgaFp zwcv7tSWyvrTEIbZK0LcN9lrqS/BwXebYfYwlSxxae2QGV4Zi3mQNn7A9aEX98sVZkai J3VAvUFrXQ7GHxCSfJDMKiG3sIPe3ZD5hYdkvT3xoi1df81oAdWt5c2X5K9M26i2jF3j IATw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0Mx9gDgfVzLcfomRQwNqW8Xjz+dKMZ5hPn8VtOlsN/Y=; b=BMpRDuQJxLVakaru0iqjST0hySSldUzbY+HqhZCUmBtnnK2DrSO25xofQXZZZ5fsQw sJYnN5sU5JWVEiVo6540ogG7/OhLewsXOy2+f/SFRqFErpzvlZZg8YascXXW+JQjf9MW qseqP/+hMJzBysQS6JRA6XeOsE8C0leNwhOF59rUVMOvmFyLgnqNo1AX8Ao+y0kpZUoo D0faOjDdeGLk36PRQ+PxMuX+arkkdoJkELys8mrvJtZuHly202i3/YMd6Ds2lSgq/Iu5 9L0qlA/bjVlHzdrQoV9JOvF8znzLUm1KF4EuKjjBRsDyZMMHazfoG7ZpgVnamYghS5Q5 xgJA== 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 oz18-20020a1709077d9200b0094a51956f6dsi4191503ejc.142.2023.04.09.23.44.07; Sun, 09 Apr 2023 23:44:32 -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 S229693AbjDJGjY (ORCPT + 99 others); Mon, 10 Apr 2023 02:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbjDJGjX (ORCPT ); Mon, 10 Apr 2023 02:39:23 -0400 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCB5B40E0 for ; Sun, 9 Apr 2023 23:39:21 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R451e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VfhGV3r_1681108758; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfhGV3r_1681108758) by smtp.aliyun-inc.com; Mon, 10 Apr 2023 14:39:18 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] erofs: handle long xattr name prefixes properly Date: Mon, 10 Apr 2023 14:39:18 +0800 Message-Id: <20230410063918.47215-1-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-7-jefflexu@linux.alibaba.com> References: <20230407141710.113882-7-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, 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 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 --- v2: remove "idx" temporary variable (Gao Xiang) --- fs/erofs/xattr.c | 57 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 684571e83a2c..4ad290b6acb7 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -301,11 +301,38 @@ 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); + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); + + 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 +514,24 @@ 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); + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); + + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) + return 1; + 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 +539,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; } -- 2.19.1.6.gb485710b