From patchwork Tue Oct 18 22:37:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13011127 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 62050C4332F for ; Tue, 18 Oct 2022 22:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbiJRWny (ORCPT ); Tue, 18 Oct 2022 18:43:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbiJRWnw (ORCPT ); Tue, 18 Oct 2022 18:43:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B65D8B7EEE for ; Tue, 18 Oct 2022 15:43:50 -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 4AABB6170E for ; Tue, 18 Oct 2022 22:43:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70921C433D6; Tue, 18 Oct 2022 22:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666133029; bh=zhorUzccnj4fCYEMYcILKuGLYfRQ/Z25KahCPnqRaX8=; h=From:To:Cc:Subject:Date:From; b=odfFc63xtigsTnfnTrAALBdlwigpQWcz8ngnG2AVafHF/4N+B7diiuY2FjUUpvK1P V56pTCZFHHYx7RY9GV9Za28j+eNCpn2pdKGnL3X5KC3dNyDrtIXaFx4fn2JUsKk2pb ZNtvVR/WS7SfU1j3KD3+0wNEXj397M8fgULtXLI2tNYNzkZaObxI5gSR9wFRrB1gJj 412rhypn8tVL51Jvihdo9h5yhx0Cq7Lo7Qgh0RKTQafkUBkJ2BOXJ8arVTZSfxYlW9 bQ77ol51g4ZntrM6qC1Mdb+fu5cq9p+k0COmC52VSUp7nuZOnSlhcpaARtjVPRaZdO BCz3hf8l+wmOA== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/3] NFSv4.2: Clear FATTR4_WORD2_SECURITY_LABEL when done decoding Date: Tue, 18 Oct 2022 18:37:21 -0400 Message-Id: <20221018223723.21242-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 Tue Oct 18 22:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13011128 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 253EEC433FE for ; Tue, 18 Oct 2022 22:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbiJRWnx (ORCPT ); Tue, 18 Oct 2022 18:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbiJRWnw (ORCPT ); Tue, 18 Oct 2022 18:43:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33119D2586 for ; Tue, 18 Oct 2022 15:43:51 -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 C726D61707 for ; Tue, 18 Oct 2022 22:43:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8F23C433C1; Tue, 18 Oct 2022 22:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666133030; bh=t2/xg3pT7kkeTRUALvA7eHeItxqCkGEC5tZzOF2LVPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRlNCOqq6ivJxGM8WQYsLzIAy3Be3WcsACYFvQgQKNXH8FEip5ahTScCHgFQ1zxOq VTvVz9uXID08jYxIxpymgLiMRaWC7m7t2jq6lGYygwD3i3i9Hrt8dlNwGHVQ8MnxLy yCJdzwG8TBmx9TCxzJsvIlG7ITCDHdbW3UvhcL3pazew8e0pZOUXvyTXv0/vS9c6DG /0+dw+ZFjcZ1GiLECv+8oT7Dvh/IpF0EqoKDv8n2/PjKTcPI1i8T253jGaE1OQOXYU 74JR3nCgrzHtfLiSmG7YeayXuQbOx8sO8ouk4Ws4nNYdvjqQiHx2M7iLg71giBxQNA FfWGsQPk96W5Q== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/3] NFSv4.2: Always decode the security label Date: Tue, 18 Oct 2022 18:37:22 -0400 Message-Id: <20221018223723.21242-2-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221018223723.21242-1-trondmy@kernel.org> References: <20221018223723.21242-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 Tue Oct 18 22:37:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13011129 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 E9D28C43217 for ; Tue, 18 Oct 2022 22:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbiJRWnz (ORCPT ); Tue, 18 Oct 2022 18:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbiJRWnw (ORCPT ); Tue, 18 Oct 2022 18:43:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC9FE8A7E8 for ; Tue, 18 Oct 2022 15:43:51 -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 4994F61717 for ; Tue, 18 Oct 2022 22:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D58BC433D7; Tue, 18 Oct 2022 22:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666133030; bh=uwCVdX1ulfgefYmg7XZs99cD0gzgSY50547f4XFvpF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=epNgVUfF3nksWS3wK354Q9oyXDvTFIu6Ocq9Jct0gHFIE3sJeuzepaAhiJwnkNzcU egtUIR3UNZlt2dKpjAelMc4jBm8d7E/tzVoNB/6tQXZl/DG7jLgILuw+Z8PD9n3NC4 5lwc1u6fIGpebw1fcLo9IMtuxof3G3db3joE6cRsCW3jpPoZZkqyYNLxXjsajgXaL5 viozJP0ICKNnCT1SUhe1rVJE7O6cZLwXLss6v6POz9XdixdfjDQIHuhfVu78o1Touj coVSNdgAxbRiZf5QDS0e/Sp33ULSlKqx354AjTrXnSBaG+EDPd1QvSWILfoxim1frF hVQ85x8q3jtzw== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/3] NFSv4.2: Fix a memory stomp in decode_attr_security_label Date: Tue, 18 Oct 2022 18:37:23 -0400 Message-Id: <20221018223723.21242-3-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221018223723.21242-2-trondmy@kernel.org> References: <20221018223723.21242-1-trondmy@kernel.org> <20221018223723.21242-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;