From patchwork Wed Oct 19 17:36:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13012237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF9DDC433FE for ; Wed, 19 Oct 2022 17:43:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbiJSRnn (ORCPT ); Wed, 19 Oct 2022 13:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbiJSRnn (ORCPT ); Wed, 19 Oct 2022 13:43:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F5261C5E15 for ; Wed, 19 Oct 2022 10:43:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D674FB82572 for ; Wed, 19 Oct 2022 17:43:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 483EAC433C1; Wed, 19 Oct 2022 17:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666201418; bh=zhorUzccnj4fCYEMYcILKuGLYfRQ/Z25KahCPnqRaX8=; h=From:To:Cc:Subject:Date:From; b=pMtxroiky/lQMR2Iw10s8ivBm6wRtnuK6KsElu5NqxHYsdFIKkUMPU7PFdQdMZ7EY YIYvN+JJLZAG3OpulHoGcnyASX57LLZQcf3YDgwl+UjIy1xBhuNn6tjVfAo/damVIW MxnGWfY/7JflbHrVfDEKO8gM4JAqmmHgrKQvc7ZnxBVWpQlmvdLPuKQ3EtzKmcC2+5 JNjLKP1XNZvK85+PCk8HgDxKWEVKQSXD5Lt2hudOO+GOwv73Vur/L2gnD3dsQOIq2A lEnOc0VaWNqkaJNIK3uB63mwI4dYg5/lP5ZF5VEPAtTeQQdvnyh3wmkauXyEtizyBz DgLcvs3TID+rg== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 1/4] NFSv4.2: Clear FATTR4_WORD2_SECURITY_LABEL when done decoding Date: Wed, 19 Oct 2022 13:36:48 -0400 Message-Id: <20221019173651.32096-1-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust We need to clear the FATTR4_WORD2_SECURITY_LABEL bitmap flag irrespective of whether or not the label is too long. Fixes: aa9c2669626c ("NFS: Client implementation of Labeled-NFS") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index acfe5f4bda48..8c5298e37f0f 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -4234,6 +4234,7 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, p = xdr_inline_decode(xdr, len); if (unlikely(!p)) return -EIO; + bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; if (len < NFS4_MAXLABELLEN) { if (label) { if (label->len) { @@ -4246,7 +4247,6 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, label->lfs = lfs; status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; } - bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; } else printk(KERN_WARNING "%s: label too long (%u)!\n", __func__, len); From patchwork Wed Oct 19 17:36:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13012238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07701C4332F for ; Wed, 19 Oct 2022 17:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbiJSRnp (ORCPT ); Wed, 19 Oct 2022 13:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230349AbiJSRno (ORCPT ); Wed, 19 Oct 2022 13:43:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D641C2F08 for ; Wed, 19 Oct 2022 10:43:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6A3B2B81E62 for ; Wed, 19 Oct 2022 17:43:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA572C433D7; Wed, 19 Oct 2022 17:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666201419; bh=t2/xg3pT7kkeTRUALvA7eHeItxqCkGEC5tZzOF2LVPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pkftqZ6arxFo9KTPueBx6JXeVMkDJ35jbGREQC7V0kD+TbQhVF0kSkMj2gSDRcQJ5 pcNJ/QMwa+euS+wy8pykUKtAIuZ2f0jt5aVhM13BlrWymoriKOFsab3rJJDGf7+U3h MOq3ptiD1xWiYLcEEaJ3dj/zHFe+xtB90839wpNqm3z6UxIzznWX1UMBC9A3ReIM/L VSrgK4C7iPxCxJvZMyiJOjksczB67Brdq0TLmZsnLGMLk2YcvcMutws9svK7U5A+Mi QWmq8uz+90KodG3WbzEY8xts70Jyb8I7NUVAqPNqmh6c9mgmyDYN4z2fVKKqPNUmfC t0qBTjLMkyC8g== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 2/4] NFSv4.2: Always decode the security label Date: Wed, 19 Oct 2022 13:36:49 -0400 Message-Id: <20221019173651.32096-2-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019173651.32096-1-trondmy@kernel.org> References: <20221019173651.32096-1-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If the server returns a reply that includes a security label, then we must decode it whether or not we can store the results. Fixes: 1e2f67da8931 ("NFS: Remove the nfs4_label argument from decode_getattr_*() functions") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4xdr.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 8c5298e37f0f..9103e022376a 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -4755,12 +4755,10 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, if (status < 0) goto xdr_error; - if (fattr->label) { - status = decode_attr_security_label(xdr, bitmap, fattr->label); - if (status < 0) - goto xdr_error; - fattr->valid |= status; - } + status = decode_attr_security_label(xdr, bitmap, fattr->label); + if (status < 0) + goto xdr_error; + fattr->valid |= status; xdr_error: dprintk("%s: xdr returned %d\n", __func__, -status); From patchwork Wed Oct 19 17:36:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13012240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0552BC433FE for ; Wed, 19 Oct 2022 17:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230522AbiJSRnr (ORCPT ); Wed, 19 Oct 2022 13:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbiJSRno (ORCPT ); Wed, 19 Oct 2022 13:43:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A08631C4909 for ; Wed, 19 Oct 2022 10:43:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CF699B8259D for ; Wed, 19 Oct 2022 17:43:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E726C433B5; Wed, 19 Oct 2022 17:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666201419; bh=uwCVdX1ulfgefYmg7XZs99cD0gzgSY50547f4XFvpF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2PiE+5fvXpe0j7d3qjrUux3sNXsjtnAVJb0efiWHvqRvz+b+LIcNeN6/RTlq7eYk kfzeQQagn6FiYccnIDrfBCRmbYme09i/6D26l/RTv4bsgMtPJlpnyFnF9bo8BRbYjU joM115Pq3UL35+T9n+TYONv2kN7h/5iSJTXAQtbuohg/zFlXhb1qLPTmrsDCbcsagw HDIVkRyeutpZtNezRIH3e4+B/Eu3VybI9eGAq5pNsSfCqzpbxCPuNB5EXDtJ72NcpN MhYqgenHv85Xk3elD51lqutB6x/wTH5DrPdKvuyf7+jI6rDgQH5zCDL7glgCLyukQm DRY5xv20seJZg== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 3/4] NFSv4.2: Fix a memory stomp in decode_attr_security_label Date: Wed, 19 Oct 2022 13:36:50 -0400 Message-Id: <20221019173651.32096-3-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019173651.32096-2-trondmy@kernel.org> References: <20221019173651.32096-1-trondmy@kernel.org> <20221019173651.32096-2-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust We must not change the value of label->len if it is zero, since that indicates we stored a label. Fixes: b4487b935452 ("nfs: Fix getxattr kernel panic and memory overflow") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4xdr.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 9103e022376a..deec76cf5afe 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -4236,12 +4236,10 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, return -EIO; bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; if (len < NFS4_MAXLABELLEN) { - if (label) { - if (label->len) { - if (label->len < len) - return -ERANGE; - memcpy(label->label, p, len); - } + if (label && label->len) { + if (label->len < len) + return -ERANGE; + memcpy(label->label, p, len); label->len = len; label->pi = pi; label->lfs = lfs; From patchwork Wed Oct 19 17:36:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13012239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00CF1C43217 for ; Wed, 19 Oct 2022 17:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbiJSRnp (ORCPT ); Wed, 19 Oct 2022 13:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230522AbiJSRno (ORCPT ); Wed, 19 Oct 2022 13:43:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F4351C5A63 for ; Wed, 19 Oct 2022 10:43:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A652961978 for ; Wed, 19 Oct 2022 17:43:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA3EFC43470; Wed, 19 Oct 2022 17:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666201420; bh=7lDpbBXJKkNTE1Dc1QHMNBNj9/EJ8YDwHvd2BCTRqwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=auqUq2ojBx3uZi70dV5FTNx0Dq8wJQ8t89Z8LDatq/MTvijpgXqlJRVyYABHk6tRs Rfgq+ey8eCOFnqhr1Ti3UAZAi5yMwomxQw/ANJ9IsJ908k2g+0FFJZeFRR6SG3aT0I YKCFiqbQ6aBW6pL+rp/x1N1qc0B2NhRq15zVOGXuCQaieQieNK6yJsfSRLVq661hoG FdQXBBq2tRn+/pGBvcxnj2/89vOsEHHTpGC1Ie6oU9RdsIVkKhHFHuBUGDAnPTMOsL C88Y2SuprAPPNkvsrA4W+YrQGRnEVaakexPjfo4G8mtV/KH8YcJnSTtAh31gPHRCTV bi9pqRb+DPeYw== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 4/4] NFSv4.2: Fix initialisation of struct nfs4_label Date: Wed, 19 Oct 2022 13:36:51 -0400 Message-Id: <20221019173651.32096-4-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019173651.32096-3-trondmy@kernel.org> References: <20221019173651.32096-1-trondmy@kernel.org> <20221019173651.32096-2-trondmy@kernel.org> <20221019173651.32096-3-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust The call to nfs4_label_init_security() should return a fully initialised label. Fixes: aa9c2669626c ("NFS: Client implementation of Labeled-NFS") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 3ed14a2a84a4..0ae48498c174 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -122,6 +122,11 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry, if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) return NULL; + label->lfs = 0; + label->pi = 0; + label->len = 0; + label->label = NULL; + err = security_dentry_init_security(dentry, sattr->ia_mode, &dentry->d_name, NULL, (void **)&label->label, &label->len); @@ -3795,7 +3800,7 @@ nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr, int *opened) { struct nfs4_state *state; - struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; + struct nfs4_label l, *label; label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); @@ -4681,7 +4686,7 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, int flags) { struct nfs_server *server = NFS_SERVER(dir); - struct nfs4_label l, *ilabel = NULL; + struct nfs4_label l, *ilabel; struct nfs_open_context *ctx; struct nfs4_state *state; int status = 0; @@ -5032,7 +5037,7 @@ static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, struct nfs4_exception exception = { .interruptible = true, }; - struct nfs4_label l, *label = NULL; + struct nfs4_label l, *label; int err; label = nfs4_label_init_security(dir, dentry, sattr, &l); @@ -5073,7 +5078,7 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, struct nfs4_exception exception = { .interruptible = true, }; - struct nfs4_label l, *label = NULL; + struct nfs4_label l, *label; int err; label = nfs4_label_init_security(dir, dentry, sattr, &l); @@ -5192,7 +5197,7 @@ static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, struct nfs4_exception exception = { .interruptible = true, }; - struct nfs4_label l, *label = NULL; + struct nfs4_label l, *label; int err; label = nfs4_label_init_security(dir, dentry, sattr, &l);