Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp972651rwb; Thu, 11 Aug 2022 13:18:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7AniT7WhC6tBRQCHfN4uIZ7+5lZn9mEU3QBm7p1iKhgVghWiVeLP6LaQa2VJUEL416/C3y X-Received: by 2002:a17:907:9808:b0:731:5835:4ac7 with SMTP id ji8-20020a170907980800b0073158354ac7mr479832ejc.125.1660249101217; Thu, 11 Aug 2022 13:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660249101; cv=none; d=google.com; s=arc-20160816; b=nJQAdZxnpgtpRnsF0oZZjYRWjPf7r/qe0Gtyc1pzsVEK5WwXTpcQ1I33Y7E5g/SXo+ 8n4DoULlDMI15GOGWiW+8RtkjEHp5HelKRCBfEqsrvjzKkAFXB/NK9zl6jlHrtCiWuGR CgE9e47aQb0dTGpJyDBfGx5MYR+ZVb4KcIsB1fzroLCGM1wia3kjsK8Z5E2NpdeZKsU2 Dy70BUWFEbz5nYLSrOHW/H9sHJVZjogM0/5QktnVYdM9Tjgrqu6Ewcut9PYHoabvZ4X5 O6IycRD5ZsGxscbmTOA9rmQaph4cKILzl9f+9fDm9ytFHf8gHADmaJW6C4Yi3lTDSMUz 8K2Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=0NsLBelydEYDezySxkM4ONU4gYfEyGwSacjLIPXy2w0=; b=en/QTVGHmX0J2L4jmdI8AvowU+/YlWfU2rHlnXjOIxOdklFOwEE/R+Dq/e15yv7YwB 55bsCfwBNp4ioJhSGKYTTSPiXwDMPpcwZXpbKRyA2av0792RYcvE3Z2GyQ6SVjg6uqU8 qmUqunHoUHuuRxDhTWgld0QcOfWh/fFYfRtVo6mqwB2R1tyFyCQ6+FzhyBKXdNxX8Lcs DH1k52abx8GmX2M+hwkhBpE18oTvlvhOHjFkPfUFwF5JhoT+5AEzvVWkDiZ3pP5jmYs0 xmFiy+OVfENxwfTpkQVh+ztDgitO+PHDeMS3llURkclplGJ6yFllgVtisGJVp+NVKMzw M8IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MbcBKb3I; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz31-20020a1709077d9f00b007306f2ffcc7si121658ejc.345.2022.08.11.13.17.44; Thu, 11 Aug 2022 13:18:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MbcBKb3I; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235639AbiHKTtB (ORCPT + 99 others); Thu, 11 Aug 2022 15:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231131AbiHKTtA (ORCPT ); Thu, 11 Aug 2022 15:49:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 299983206E for ; Thu, 11 Aug 2022 12:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660247339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=0NsLBelydEYDezySxkM4ONU4gYfEyGwSacjLIPXy2w0=; b=MbcBKb3IYrFYCCDQ0gwSEPYO7I/5/vMJJyk2GII1kyPUyBOpY2QkIBbnYxfONJVyb7WvFr fNf8Wd36eMiZOIyXyWIngL/RblXy6JiBXI8FBFOCWmRCqMQ/CaGaIwvLn7PPaUn2FgUQng WnponygoZ7Zks8KG7exduqZ+Qe9r64g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-OJ9NFiJLNz6I-Wx4D2rQXA-1; Thu, 11 Aug 2022 15:48:57 -0400 X-MC-Unique: OJ9NFiJLNz6I-Wx4D2rQXA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72C5C8115B1 for ; Thu, 11 Aug 2022 19:48:57 +0000 (UTC) Received: from kdsouza.com (vm-238-64.vmware.gsslab.pnq2.redhat.com [10.74.238.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 557AF14152E0; Thu, 11 Aug 2022 19:48:56 +0000 (UTC) From: Kenneth D'souza To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, kdsouza@redhat.com Subject: [PATCH v2] libnfs4acl: Check file mode before getxattr call Date: Thu, 11 Aug 2022 14:48:34 -0500 Message-Id: <20220811194834.470072-1-kdsouza@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-nfs@vger.kernel.org Currently we are checking file mode after getxattr call. Due to this the return value would be 0, which would change the getxattr return value. As xattr_size will be 0, nfs4_getfacl will fail with error EINVAL. This patch fixes this issue by moving the file mode check before getxattr call. Signed-off-by: Kenneth D'souza --- libnfs4acl/nfs4_getacl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libnfs4acl/nfs4_getacl.c b/libnfs4acl/nfs4_getacl.c index 7821da3..aace5cd 100644 --- a/libnfs4acl/nfs4_getacl.c +++ b/libnfs4acl/nfs4_getacl.c @@ -39,6 +39,13 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path, return NULL; } + ret = stat(path, &st); + if (ret == -1) + goto err; + + if (S_ISDIR(st.st_mode)) + iflags = NFS4_ACL_ISDIR; + /* find necessary buffer size */ ret = getxattr(path, xattr_name, NULL, 0); if (ret == -1) @@ -53,13 +60,6 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path, if (ret == -1) goto err_free; - ret = stat(path, &st); - if (ret == -1) - goto err_free; - - if (S_ISDIR(st.st_mode)) - iflags = NFS4_ACL_ISDIR; - acl = acl_nfs41_xattr_load(buf, ret, iflags, type); free(buf); -- 2.31.1