From patchwork Sun Jan 8 16:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092576 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 DCCD7C53210 for ; Sun, 8 Jan 2023 16:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232950AbjAHQc4 (ORCPT ); Sun, 8 Jan 2023 11:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236150AbjAHQ2g (ORCPT ); Sun, 8 Jan 2023 11:28:36 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B3E4DEA7 for ; Sun, 8 Jan 2023 08:28:35 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 87B9FCE0B6A for ; Sun, 8 Jan 2023 16:28:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75314C433D2 for ; Sun, 8 Jan 2023 16:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195311; bh=h3WbmLS7lqbzJy8Ex1BkBSAASCbOy3167ohrofAJb8o=; h=Subject:From:To:Date:In-Reply-To:References:From; b=kgzXmL95HVdkE/BR03mY7JFYCsITbm3K79MN+ELkTXGa9x1P5Qwk++BEIsu73tldc 6N+D4GglAV3kHix/sN3E5CN2piOKIVlBNQQISeE2yFvwm2y6Vzgyr+nLZyzocNMqZk 76imDDwnkwRf53e+T9CeicWrI/uV4DwBlYuvV+nESrS6FIM0Xp0em8Z8796mxoH1RF m87q8NGD1oWi4LOdULQ3ELsVF9c9l8W/jebqkWSZ/sjLh8Z9RW5JYAUJ6TpOzVMxa8 xSIJb5mPnNHtjzvSc8o4hvZXXgLtReZaKwOfsjhUK610xcnb8pMzzD02b1mXILUgD+ IbpvEWD6EONEA== Subject: [PATCH v1 01/27] SUNRPC: Clean up svcauth_gss_release() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:28:30 -0500 Message-ID: <167319531054.7490.10405247832294580026.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Now that upper layers use an xdr_stream to track the construction of each RPC Reply message, resbuf->len is kept up-to-date automatically. There's no need to recompute it in svc_gss_release(). Signed-off-by: Chuck Lever Reviewed-by: Jeff Layton --- net/sunrpc/auth_gss/svcauth_gss.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 2e603358fae1..4a576ed7aa32 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -969,12 +969,6 @@ svcauth_gss_unwrap_integ(struct svc_rqst *rqstp, u32 seq, struct gss_ctx *ctx) return -EINVAL; } -static inline int -total_buf_len(struct xdr_buf *buf) -{ - return buf->head[0].iov_len + buf->page_len + buf->tail[0].iov_len; -} - /* * RFC 2203, Section 5.3.2.3 * @@ -1882,14 +1876,25 @@ svcauth_gss_wrap_resp_priv(struct svc_rqst *rqstp) return 0; } +/** + * svcauth_gss_release - Wrap payload and release resources + * @rqstp: RPC transaction context + * + * Return values: + * %0: the Reply is ready to be sent + * %-ENOMEM: failed to allocate memory + * %-EINVAL: encoding error + * + * XXX: These return values do not match the return values documented + * for the auth_ops ->release method in linux/sunrpc/svcauth.h. + */ static int svcauth_gss_release(struct svc_rqst *rqstp) { - struct gss_svc_data *gsd = (struct gss_svc_data *)rqstp->rq_auth_data; - struct rpc_gss_wire_cred *gc; - struct xdr_buf *resbuf = &rqstp->rq_res; - int stat = -EINVAL; struct sunrpc_net *sn = net_generic(SVC_NET(rqstp), sunrpc_net_id); + struct gss_svc_data *gsd = rqstp->rq_auth_data; + struct rpc_gss_wire_cred *gc; + int stat; if (!gsd) goto out; @@ -1899,10 +1904,7 @@ svcauth_gss_release(struct svc_rqst *rqstp) /* Release can be called twice, but we only wrap once. */ if (gsd->verf_start == NULL) goto out; - /* normally not set till svc_send, but we need it here: */ - /* XXX: what for? Do we mess it up the moment we call svc_putu32 - * or whatever? */ - resbuf->len = total_buf_len(resbuf); + switch (gc->gc_svc) { case RPC_GSS_SVC_NONE: break; From patchwork Sun Jan 8 16:28:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092577 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 EB82AC63797 for ; Sun, 8 Jan 2023 16:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230323AbjAHQc4 (ORCPT ); Sun, 8 Jan 2023 11:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236174AbjAHQ2n (ORCPT ); Sun, 8 Jan 2023 11:28:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25D5BD2FC for ; Sun, 8 Jan 2023 08:28:41 -0800 (PST) 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 17C28B801C1 for ; Sun, 8 Jan 2023 16:28:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A87ABC433D2 for ; Sun, 8 Jan 2023 16:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195317; bh=QJuJWSyOSQRwAyRn2YOsINULzLUYJplZ8WlDYg5Qhrs=; h=Subject:From:To:Date:In-Reply-To:References:From; b=OnnZGh/0pyCunuWghP5WnFk3E0Gez22Aa55OgzpA13MRTyxSTLB2BL2jFbWlUAzN1 LLsgBRb/8jD+o0gSl9X2hjrGmlptY1fEalqTRLHCShxtHiuKz4S/42TEQRJOXMghEh gLrD36MjRlBkC9hDidoY1NxRsXKdDrjM3KskyAfvPYQ+YVFVkLV5gV/dV3FFZ14tXM lP0ESMtZ2qV5P4IjX021NPkKM1C4fPLIxngtAOjn6z/YGDUfH86wUK5VEbr5rtN2b+ 9PHNks9FHMYjpYRDe9rrWdXsLzoSmS5ninVYaBbg49OnOYcDckKCIl+p47Qa9/Brr1 WDogwvr14hC4A== Subject: [PATCH v1 02/27] SUNRPC: Rename automatic variables in svcauth_gss_wrap_resp_integ() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:28:36 -0500 Message-ID: <167319531676.7490.8981785713795990569.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Clean up: To help orient readers, name the stack variables to match the XDR field names. Additionally, the explicit type cast on @gsd is unnecessary; and @resbuf is renamed to match the variable naming in the unwrap functions. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 70 +++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 4a576ed7aa32..fe0bd0ad8ace 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1758,49 +1758,65 @@ svcauth_gss_prepare_to_wrap(struct xdr_buf *resbuf, struct gss_svc_data *gsd) return p; } -static inline int -svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) +/* + * RFC 2203, Section 5.3.2.2 + * + * struct rpc_gss_integ_data { + * opaque databody_integ<>; + * opaque checksum<>; + * }; + * + * struct rpc_gss_data_t { + * unsigned int seq_num; + * proc_req_arg_t arg; + * }; + * + * The RPC Reply message has already been XDR-encoded. rq_res_stream + * is now positioned so that the checksum can be written just past + * the RPC Reply message. + */ +static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) { - struct gss_svc_data *gsd = (struct gss_svc_data *)rqstp->rq_auth_data; + struct gss_svc_data *gsd = rqstp->rq_auth_data; struct rpc_gss_wire_cred *gc = &gsd->clcred; - struct xdr_buf *resbuf = &rqstp->rq_res; - struct xdr_buf integ_buf; - struct xdr_netobj mic; + struct xdr_buf *buf = &rqstp->rq_res; + struct xdr_buf databody_integ; + struct xdr_netobj checksum; struct kvec *resv; + u32 offset, len; __be32 *p; - int integ_offset, integ_len; int stat = -EINVAL; - p = svcauth_gss_prepare_to_wrap(resbuf, gsd); + p = svcauth_gss_prepare_to_wrap(buf, gsd); if (p == NULL) goto out; - integ_offset = (u8 *)(p + 1) - (u8 *)resbuf->head[0].iov_base; - integ_len = resbuf->len - integ_offset; - if (integ_len & 3) + offset = (u8 *)(p + 1) - (u8 *)buf->head[0].iov_base; + len = buf->len - offset; + if (len & 3) goto out; - *p++ = htonl(integ_len); + *p++ = htonl(len); *p++ = htonl(gc->gc_seq); - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) { + if (xdr_buf_subsegment(buf, &databody_integ, offset, len)) { WARN_ON_ONCE(1); goto out_err; } - if (resbuf->tail[0].iov_base == NULL) { - if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) + if (!buf->tail[0].iov_base) { + if (buf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) goto out_err; - resbuf->tail[0].iov_base = resbuf->head[0].iov_base - + resbuf->head[0].iov_len; - resbuf->tail[0].iov_len = 0; + buf->tail[0].iov_base = buf->head[0].iov_base + + buf->head[0].iov_len; + buf->tail[0].iov_len = 0; } - resv = &resbuf->tail[0]; - mic.data = (u8 *)resv->iov_base + resv->iov_len + 4; - if (gss_get_mic(gsd->rsci->mechctx, &integ_buf, &mic)) + resv = &buf->tail[0]; + checksum.data = (u8 *)resv->iov_base + resv->iov_len + 4; + if (gss_get_mic(gsd->rsci->mechctx, &databody_integ, &checksum)) goto out_err; - svc_putnl(resv, mic.len); - memset(mic.data + mic.len, 0, - round_up_to_quad(mic.len) - mic.len); - resv->iov_len += XDR_QUADLEN(mic.len) << 2; + svc_putnl(resv, checksum.len); + memset(checksum.data + checksum.len, 0, + round_up_to_quad(checksum.len) - checksum.len); + resv->iov_len += XDR_QUADLEN(checksum.len) << 2; /* not strictly required: */ - resbuf->len += XDR_QUADLEN(mic.len) << 2; + buf->len += XDR_QUADLEN(checksum.len) << 2; if (resv->iov_len > PAGE_SIZE) goto out_err; out: @@ -1909,7 +1925,7 @@ svcauth_gss_release(struct svc_rqst *rqstp) case RPC_GSS_SVC_NONE: break; case RPC_GSS_SVC_INTEGRITY: - stat = svcauth_gss_wrap_resp_integ(rqstp); + stat = svcauth_gss_wrap_integ(rqstp); if (stat) goto out_err; break; From patchwork Sun Jan 8 16:28:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092575 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 F1003C54EBD for ; Sun, 8 Jan 2023 16:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbjAHQcz (ORCPT ); Sun, 8 Jan 2023 11:32:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236191AbjAHQ2r (ORCPT ); Sun, 8 Jan 2023 11:28:47 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 897071E1 for ; Sun, 8 Jan 2023 08:28:46 -0800 (PST) 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 48EDEB801C1 for ; Sun, 8 Jan 2023 16:28:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD7D5C433D2 for ; Sun, 8 Jan 2023 16:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195324; bh=CgQt5z+QmRjPlG92uuk3VbwwdRA8HOGso7urp92tBzE=; h=Subject:From:To:Date:In-Reply-To:References:From; b=bzdOdsaT2nr6okbCWZpOjdIphWsp7MFk/w+iuguPK8F8OrhXJhqxrtdb4igJ7e4zp tK4J/IaqCGMC88AikhTH686hHX5dG4v6WBK14JOWQ1BeeW0GE5RYwq9D+XithaWvvW ql1X70/yZnx3Oot/IXmnGnnYAqTsLa0EYlsASFpJnGksi3danmerp46JK0Fay2RrEA Dg+r12moguQ2ImnEPW6T2xo9VUl15hAw6FnWu0rZnCdWwtqcE70JlaUHdCfoW0Eqkt WN6FgZoxd0VoOygPEJ8bxTOBSr5h/QEow8RflxvDqFwJkiXd7L2R6CTl2aFfTd22Kc mn9JsgwEQ9Ryg== Subject: [PATCH v1 03/27] SUNRPC: Record gss_get_mic() errors in svcauth_gss_wrap_integ() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:28:42 -0500 Message-ID: <167319532298.7490.6629715101889997663.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever An error computing the checksum here is an exceptional event. Signed-off-by: Chuck Lever --- include/trace/events/rpcgss.h | 1 + net/sunrpc/auth_gss/svcauth_gss.c | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/trace/events/rpcgss.h b/include/trace/events/rpcgss.h index 3f121eed369e..261751ac241c 100644 --- a/include/trace/events/rpcgss.h +++ b/include/trace/events/rpcgss.h @@ -208,6 +208,7 @@ DECLARE_EVENT_CLASS(rpcgss_svc_gssapi_class, DEFINE_SVC_GSSAPI_EVENT(unwrap); DEFINE_SVC_GSSAPI_EVENT(mic); +DEFINE_SVC_GSSAPI_EVENT(get_mic); TRACE_EVENT(rpcgss_svc_unwrap_failed, TP_PROTO( diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index fe0bd0ad8ace..2d1e8431e903 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1782,10 +1782,9 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) struct xdr_buf *buf = &rqstp->rq_res; struct xdr_buf databody_integ; struct xdr_netobj checksum; + u32 offset, len, maj_stat; struct kvec *resv; - u32 offset, len; __be32 *p; - int stat = -EINVAL; p = svcauth_gss_prepare_to_wrap(buf, gsd); if (p == NULL) @@ -1796,21 +1795,20 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) goto out; *p++ = htonl(len); *p++ = htonl(gc->gc_seq); - if (xdr_buf_subsegment(buf, &databody_integ, offset, len)) { - WARN_ON_ONCE(1); - goto out_err; - } + if (xdr_buf_subsegment(buf, &databody_integ, offset, len)) + goto wrap_failed; if (!buf->tail[0].iov_base) { if (buf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) - goto out_err; + goto wrap_failed; buf->tail[0].iov_base = buf->head[0].iov_base + buf->head[0].iov_len; buf->tail[0].iov_len = 0; } resv = &buf->tail[0]; checksum.data = (u8 *)resv->iov_base + resv->iov_len + 4; - if (gss_get_mic(gsd->rsci->mechctx, &databody_integ, &checksum)) - goto out_err; + maj_stat = gss_get_mic(gsd->rsci->mechctx, &databody_integ, &checksum); + if (maj_stat != GSS_S_COMPLETE) + goto bad_mic; svc_putnl(resv, checksum.len); memset(checksum.data + checksum.len, 0, round_up_to_quad(checksum.len) - checksum.len); @@ -1818,11 +1816,13 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) /* not strictly required: */ buf->len += XDR_QUADLEN(checksum.len) << 2; if (resv->iov_len > PAGE_SIZE) - goto out_err; + goto wrap_failed; out: - stat = 0; -out_err: - return stat; + return 0; +bad_mic: + trace_rpcgss_svc_get_mic(rqstp, maj_stat); +wrap_failed: + return -EINVAL; } static inline int From patchwork Sun Jan 8 16:28:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092544 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 E381AC53210 for ; Sun, 8 Jan 2023 16:28:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233573AbjAHQ24 (ORCPT ); Sun, 8 Jan 2023 11:28:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234911AbjAHQ2v (ORCPT ); Sun, 8 Jan 2023 11:28:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39E411E1 for ; Sun, 8 Jan 2023 08:28:51 -0800 (PST) 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 C1A9860CA4 for ; Sun, 8 Jan 2023 16:28:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 183FEC433D2 for ; Sun, 8 Jan 2023 16:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195330; bh=3j3GF5g7jnc2jqxOrkddOI7pyogY86xCrfJVtxdbELo=; h=Subject:From:To:Date:In-Reply-To:References:From; b=BohVGQt5pXlj6IDZlsAdEkQJcWHgGtTGyBXt3a/NwLce929AKgIyH9GmvsvWhvfjw B4AerQGcRZBjrocaXcekMuXB9FAs7wXPFaOT3MeTtDgFKsSEqFASKqzRjBD3RkwMdi tPDPLJcWVf1Feks7SyDjvwdotqCkQpo/QOpqOYuo595FnAcNi9Up2VbkqbHmzC06py /W4MKrbecWwKjZogbHfSAiE5vrumYhDFLsi859YuQzAYVbBK0/4vSZDaLyfr1iufXu lE4HgREE14P6UhpuX9nafAIUslIW6aaKBUcFWS+DSqxihNo3ctrv0GqNOtCAJf19Pd tf+rRgGYYxvdA== Subject: [PATCH v1 04/27] SUNRPC: Replace checksum construction in svcauth_gss_wrap_integ() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:28:49 -0500 Message-ID: <167319532919.7490.2863207896087099817.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Replace finicky logic: Instead of trying to find scratch space in the response buffer, use the scratch buffer from struct gss_svc_data. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 2d1e8431e903..6aefe24953fa 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1797,15 +1797,8 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) *p++ = htonl(gc->gc_seq); if (xdr_buf_subsegment(buf, &databody_integ, offset, len)) goto wrap_failed; - if (!buf->tail[0].iov_base) { - if (buf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) - goto wrap_failed; - buf->tail[0].iov_base = buf->head[0].iov_base - + buf->head[0].iov_len; - buf->tail[0].iov_len = 0; - } - resv = &buf->tail[0]; - checksum.data = (u8 *)resv->iov_base + resv->iov_len + 4; + + checksum.data = gsd->gsd_scratch; maj_stat = gss_get_mic(gsd->rsci->mechctx, &databody_integ, &checksum); if (maj_stat != GSS_S_COMPLETE) goto bad_mic; From patchwork Sun Jan 8 16:28:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092545 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 D5A8FC54EBE for ; Sun, 8 Jan 2023 16:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234683AbjAHQ27 (ORCPT ); Sun, 8 Jan 2023 11:28:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233253AbjAHQ26 (ORCPT ); Sun, 8 Jan 2023 11:28:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B7D13889 for ; Sun, 8 Jan 2023 08:28:57 -0800 (PST) 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 0543860CA4 for ; Sun, 8 Jan 2023 16:28:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 535C9C433D2 for ; Sun, 8 Jan 2023 16:28:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195336; bh=c1iwYkCYWC3wYFX2GnKwRh0H8M8adsjY4fr/5BRHK0c=; h=Subject:From:To:Date:In-Reply-To:References:From; b=K0w5Wja4Hz3qzdH1LVhxJ7ik73NLrJOrUFGOup2x6N+34sIb3tzo+DxZkuojCwlxx HzvJ6cIZuu2xwduf6LOgW7RJuOPrbaigebH/Kzh9JLbBUXaC9Csr/TzrUJTU7cP8WB 8D+beoSw00/4srN1VbqqzyDYrKbUXtm+jy+xbNYcWzBVmOjt3qGTzMbwbnTBz5E8Tr DjaZ2kkedfX5Rxs2THy1hBd5QduLa6dtlJd8WC3SZgN7Kq/LX0D7mFpZjQLNo/UWA0 cgA3BuE8167OYZku+19DTMUgN6GRTYSzbsvnLE4aKl32LjfesHar/BQdhsWz80STIr KmXhjqvzklR+g== Subject: [PATCH v1 05/27] SUNRPC: Convert svcauth_gss_wrap_integ() to use xdr_stream() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:28:55 -0500 Message-ID: <167319533537.7490.14676041298155635311.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Done as part of hardening the server-side RPC header decoding path. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 6aefe24953fa..3715ff842ca1 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1778,40 +1778,39 @@ svcauth_gss_prepare_to_wrap(struct xdr_buf *resbuf, struct gss_svc_data *gsd) static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) { struct gss_svc_data *gsd = rqstp->rq_auth_data; + struct xdr_stream *xdr = &rqstp->rq_res_stream; struct rpc_gss_wire_cred *gc = &gsd->clcred; - struct xdr_buf *buf = &rqstp->rq_res; + struct xdr_buf *buf = xdr->buf; struct xdr_buf databody_integ; struct xdr_netobj checksum; u32 offset, len, maj_stat; - struct kvec *resv; __be32 *p; p = svcauth_gss_prepare_to_wrap(buf, gsd); if (p == NULL) goto out; + offset = (u8 *)(p + 1) - (u8 *)buf->head[0].iov_base; len = buf->len - offset; - if (len & 3) - goto out; - *p++ = htonl(len); - *p++ = htonl(gc->gc_seq); if (xdr_buf_subsegment(buf, &databody_integ, offset, len)) goto wrap_failed; + /* Buffer space for these has already been reserved in + * svcauth_gss_accept(). */ + *p++ = cpu_to_be32(len); + *p = cpu_to_be32(gc->gc_seq); checksum.data = gsd->gsd_scratch; maj_stat = gss_get_mic(gsd->rsci->mechctx, &databody_integ, &checksum); if (maj_stat != GSS_S_COMPLETE) goto bad_mic; - svc_putnl(resv, checksum.len); - memset(checksum.data + checksum.len, 0, - round_up_to_quad(checksum.len) - checksum.len); - resv->iov_len += XDR_QUADLEN(checksum.len) << 2; - /* not strictly required: */ - buf->len += XDR_QUADLEN(checksum.len) << 2; - if (resv->iov_len > PAGE_SIZE) + + if (xdr_stream_encode_opaque(xdr, checksum.data, checksum.len) < 0) goto wrap_failed; + xdr_commit_encode(xdr); + out: return 0; + bad_mic: trace_rpcgss_svc_get_mic(rqstp, maj_stat); wrap_failed: From patchwork Sun Jan 8 16:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092546 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 2DF2EC54EBD for ; Sun, 8 Jan 2023 16:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234737AbjAHQ3H (ORCPT ); Sun, 8 Jan 2023 11:29:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234724AbjAHQ3G (ORCPT ); Sun, 8 Jan 2023 11:29:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 425CE3889 for ; Sun, 8 Jan 2023 08:29:05 -0800 (PST) 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 EF0AEB80B36 for ; Sun, 8 Jan 2023 16:29:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BC15C433D2 for ; Sun, 8 Jan 2023 16:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195342; bh=98aoESdPw0HdeCTXa5CJNdW5D+rs0Hty61qBU7rUXn8=; h=Subject:From:To:Date:In-Reply-To:References:From; b=DnHMKKwRMdEdd+jyg/KKHBBRt8Kv/NZJzv6le0fOUDZF858VW9s4d7Na9wI7yrKAy +uLwUxN/Km3CVHFN8StBGKU9nKeXDGG9qKltv4cqfn7HbBgaW8j+5O45GfPqTttOR7 auUWIdT4xywo1eFBnxCF5GlruRCJorvN7joQc2W95s40U/uof6V65twbEqcHexHXCC Df+U0zbNLmsPWcpF5Tvn7goKS/TefHr07cCKh38vyikqtRfBn/Ca9kcCtcJbxjGS7H 0GjmwVvBGmsBwtwTWv1Z2WFkiYeBgf2DTAmJGsC5xTluf9uPlzi4HIMfbz5x3YOlqJ b8ETMxyHQ13bQ== Subject: [PATCH v1 06/27] SUNRPC: Rename automatic variables in svcauth_gss_wrap_resp_priv() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:01 -0500 Message-ID: <167319534163.7490.5386134241125006813.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Clean up variable names to match the other unwrap and wrap functions. Additionally, the explicit type cast on @gsd in unnecessary; and @resbuf is renamed to match the variable naming in the unwrap functions. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 72 ++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 3715ff842ca1..f0cd89f201bc 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1817,24 +1817,35 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) return -EINVAL; } -static inline int -svcauth_gss_wrap_resp_priv(struct svc_rqst *rqstp) +/* + * RFC 2203, Section 5.3.2.3 + * + * struct rpc_gss_priv_data { + * opaque databody_priv<> + * }; + * + * struct rpc_gss_data_t { + * unsigned int seq_num; + * proc_req_arg_t arg; + * }; + */ +static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) { - struct gss_svc_data *gsd = (struct gss_svc_data *)rqstp->rq_auth_data; + struct gss_svc_data *gsd = rqstp->rq_auth_data; struct rpc_gss_wire_cred *gc = &gsd->clcred; - struct xdr_buf *resbuf = &rqstp->rq_res; + struct xdr_buf *buf = &rqstp->rq_res; struct page **inpages = NULL; - __be32 *p, *len; + __be32 *p, *lenp; int offset; int pad; - p = svcauth_gss_prepare_to_wrap(resbuf, gsd); + p = svcauth_gss_prepare_to_wrap(buf, gsd); if (p == NULL) return 0; - len = p++; - offset = (u8 *)p - (u8 *)resbuf->head[0].iov_base; + lenp = p++; + offset = (u8 *)p - (u8 *)buf->head[0].iov_base; *p++ = htonl(gc->gc_seq); - inpages = resbuf->pages; + inpages = buf->pages; /* XXX: Would be better to write some xdr helper functions for * nfs{2,3,4}xdr.c that place the data right, instead of copying: */ @@ -1845,19 +1856,19 @@ svcauth_gss_wrap_resp_priv(struct svc_rqst *rqstp) * there is RPC_MAX_AUTH_SIZE slack space available in * both the head and tail. */ - if (resbuf->tail[0].iov_base) { - if (resbuf->tail[0].iov_base >= - resbuf->head[0].iov_base + PAGE_SIZE) + if (buf->tail[0].iov_base) { + if (buf->tail[0].iov_base >= + buf->head[0].iov_base + PAGE_SIZE) return -EINVAL; - if (resbuf->tail[0].iov_base < resbuf->head[0].iov_base) + if (buf->tail[0].iov_base < buf->head[0].iov_base) return -EINVAL; - if (resbuf->tail[0].iov_len + resbuf->head[0].iov_len + if (buf->tail[0].iov_len + buf->head[0].iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) return -ENOMEM; - memmove(resbuf->tail[0].iov_base + RPC_MAX_AUTH_SIZE, - resbuf->tail[0].iov_base, - resbuf->tail[0].iov_len); - resbuf->tail[0].iov_base += RPC_MAX_AUTH_SIZE; + memmove(buf->tail[0].iov_base + RPC_MAX_AUTH_SIZE, + buf->tail[0].iov_base, + buf->tail[0].iov_len); + buf->tail[0].iov_base += RPC_MAX_AUTH_SIZE; } /* * If there is no current tail data, make sure there is @@ -1866,21 +1877,22 @@ svcauth_gss_wrap_resp_priv(struct svc_rqst *rqstp) * is RPC_MAX_AUTH_SIZE slack space available in both the * head and tail. */ - if (resbuf->tail[0].iov_base == NULL) { - if (resbuf->head[0].iov_len + 2*RPC_MAX_AUTH_SIZE > PAGE_SIZE) + if (!buf->tail[0].iov_base) { + if (buf->head[0].iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) return -ENOMEM; - resbuf->tail[0].iov_base = resbuf->head[0].iov_base - + resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE; - resbuf->tail[0].iov_len = 0; + buf->tail[0].iov_base = buf->head[0].iov_base + + buf->head[0].iov_len + RPC_MAX_AUTH_SIZE; + buf->tail[0].iov_len = 0; } - if (gss_wrap(gsd->rsci->mechctx, offset, resbuf, inpages)) + if (gss_wrap(gsd->rsci->mechctx, offset, buf, inpages)) return -ENOMEM; - *len = htonl(resbuf->len - offset); - pad = 3 - ((resbuf->len - offset - 1)&3); - p = (__be32 *)(resbuf->tail[0].iov_base + resbuf->tail[0].iov_len); + *lenp = htonl(buf->len - offset); + pad = 3 - ((buf->len - offset - 1) & 3); + p = (__be32 *)(buf->tail[0].iov_base + buf->tail[0].iov_len); memset(p, 0, pad); - resbuf->tail[0].iov_len += pad; - resbuf->len += pad; + buf->tail[0].iov_len += pad; + buf->len += pad; + return 0; } @@ -1922,7 +1934,7 @@ svcauth_gss_release(struct svc_rqst *rqstp) goto out_err; break; case RPC_GSS_SVC_PRIVACY: - stat = svcauth_gss_wrap_resp_priv(rqstp); + stat = svcauth_gss_wrap_priv(rqstp); if (stat) goto out_err; break; From patchwork Sun Jan 8 16:29:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092547 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 3C56CC54EBD for ; Sun, 8 Jan 2023 16:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234878AbjAHQ3O (ORCPT ); Sun, 8 Jan 2023 11:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234897AbjAHQ3N (ORCPT ); Sun, 8 Jan 2023 11:29:13 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B7331E1 for ; Sun, 8 Jan 2023 08:29:11 -0800 (PST) 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 25D74B801C1 for ; Sun, 8 Jan 2023 16:29:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6236C433EF for ; Sun, 8 Jan 2023 16:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195348; bh=q8ePbn7JgPU3n77v/Vqr3GIufd4WlayW8ZUdzCCFKeQ=; h=Subject:From:To:Date:In-Reply-To:References:From; b=HTZ0bYiFK5jj5vgtiUdlvPQZTAARnpPKIxAvGogVTSB43LHf9VdT6guNfcoZUsu8m y5ngtWIC3T4dIbP7S1FGJKpDdcnGMY51M8V0tlEilDhnyTq0wf5+qJ6FdpOBv+9XKS Lzoq4kiYe49HawsiY5uAHhii6/k6P16QnmDQ86hV+9Yg9LZCf8cANWDxBecglOb1ic 3rZyuw9GJmyXWo4SW35lP2/EDRkOLCYxUYvczw0+iNWIlGjJ8nER4cXRGfIkoq++Uo y8l1d+UTruiCeKjSABphCezfxfACdUxUU6U2m/kQqdopmgwxdO/TJDOFWDZy9ftlsC Hozb9aldXbwDg== Subject: [PATCH v1 07/27] SUNRPC: Record gss_wrap() errors in svcauth_gss_wrap_priv() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:07 -0500 Message-ID: <167319534785.7490.16274848447001502338.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Match the error reporting in the other unwrap and wrap functions. Signed-off-by: Chuck Lever --- include/trace/events/rpcgss.h | 21 +++++++++++++++++++++ net/sunrpc/auth_gss/svcauth_gss.c | 29 +++++++++++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/include/trace/events/rpcgss.h b/include/trace/events/rpcgss.h index 261751ac241c..ba2d96a1bc2f 100644 --- a/include/trace/events/rpcgss.h +++ b/include/trace/events/rpcgss.h @@ -206,10 +206,31 @@ DECLARE_EVENT_CLASS(rpcgss_svc_gssapi_class, ), \ TP_ARGS(rqstp, maj_stat)) +DEFINE_SVC_GSSAPI_EVENT(wrap); DEFINE_SVC_GSSAPI_EVENT(unwrap); DEFINE_SVC_GSSAPI_EVENT(mic); DEFINE_SVC_GSSAPI_EVENT(get_mic); +TRACE_EVENT(rpcgss_svc_wrap_failed, + TP_PROTO( + const struct svc_rqst *rqstp + ), + + TP_ARGS(rqstp), + + TP_STRUCT__entry( + __field(u32, xid) + __string(addr, rqstp->rq_xprt->xpt_remotebuf) + ), + + TP_fast_assign( + __entry->xid = be32_to_cpu(rqstp->rq_xid); + __assign_str(addr, rqstp->rq_xprt->xpt_remotebuf); + ), + + TP_printk("addr=%s xid=0x%08x", __get_str(addr), __entry->xid) +); + TRACE_EVENT(rpcgss_svc_unwrap_failed, TP_PROTO( const struct svc_rqst *rqstp diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index f0cd89f201bc..573b9d029709 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1813,7 +1813,9 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) bad_mic: trace_rpcgss_svc_get_mic(rqstp, maj_stat); + return -EINVAL; wrap_failed: + trace_rpcgss_svc_wrap_failed(rqstp); return -EINVAL; } @@ -1834,18 +1836,16 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) struct gss_svc_data *gsd = rqstp->rq_auth_data; struct rpc_gss_wire_cred *gc = &gsd->clcred; struct xdr_buf *buf = &rqstp->rq_res; - struct page **inpages = NULL; + u32 offset, pad, maj_stat; __be32 *p, *lenp; - int offset; - int pad; p = svcauth_gss_prepare_to_wrap(buf, gsd); if (p == NULL) return 0; + lenp = p++; offset = (u8 *)p - (u8 *)buf->head[0].iov_base; *p++ = htonl(gc->gc_seq); - inpages = buf->pages; /* XXX: Would be better to write some xdr helper functions for * nfs{2,3,4}xdr.c that place the data right, instead of copying: */ @@ -1859,12 +1859,12 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) if (buf->tail[0].iov_base) { if (buf->tail[0].iov_base >= buf->head[0].iov_base + PAGE_SIZE) - return -EINVAL; + goto wrap_failed; if (buf->tail[0].iov_base < buf->head[0].iov_base) - return -EINVAL; + goto wrap_failed; if (buf->tail[0].iov_len + buf->head[0].iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) - return -ENOMEM; + goto wrap_failed; memmove(buf->tail[0].iov_base + RPC_MAX_AUTH_SIZE, buf->tail[0].iov_base, buf->tail[0].iov_len); @@ -1879,13 +1879,16 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) */ if (!buf->tail[0].iov_base) { if (buf->head[0].iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) - return -ENOMEM; + goto wrap_failed; buf->tail[0].iov_base = buf->head[0].iov_base + buf->head[0].iov_len + RPC_MAX_AUTH_SIZE; buf->tail[0].iov_len = 0; } - if (gss_wrap(gsd->rsci->mechctx, offset, buf, inpages)) - return -ENOMEM; + + maj_stat = gss_wrap(gsd->rsci->mechctx, offset, buf, buf->pages); + if (maj_stat != GSS_S_COMPLETE) + goto bad_wrap; + *lenp = htonl(buf->len - offset); pad = 3 - ((buf->len - offset - 1) & 3); p = (__be32 *)(buf->tail[0].iov_base + buf->tail[0].iov_len); @@ -1894,6 +1897,12 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) buf->len += pad; return 0; +wrap_failed: + trace_rpcgss_svc_wrap_failed(rqstp); + return -EINVAL; +bad_wrap: + trace_rpcgss_svc_wrap(rqstp, maj_stat); + return -ENOMEM; } /** From patchwork Sun Jan 8 16:29:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092548 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 6604FC54EBD for ; Sun, 8 Jan 2023 16:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236119AbjAHQ3Z (ORCPT ); Sun, 8 Jan 2023 11:29:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236104AbjAHQ3U (ORCPT ); Sun, 8 Jan 2023 11:29:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9579BDECE for ; Sun, 8 Jan 2023 08:29:17 -0800 (PST) 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 44C9BB801C1 for ; Sun, 8 Jan 2023 16:29:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0647C433EF for ; Sun, 8 Jan 2023 16:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195355; bh=yU44dm8r/pJTTVOzENxVl4aOQ7MAaVzzz9F/BxOpfkA=; h=Subject:From:To:Date:In-Reply-To:References:From; b=jn6/j0Oy9NYi2HM9zZJfaq7t8Ukw1xHkPo0PbOH9wkyc3rqQaLEi/h9+Iw5gMt2Ai 9JHiCDtRnVMJwTQNBMV5oI4slCiecHICLtzoTkMbzResF9BUWus32ez7uNcUdprbJM 3tYx+xk1Yrv6gi3kdfym0nLX5e+alLCQYLaI/YCu7UuqmqviRciZbrnEeqy60MW2ql 7opInqvMEjHhrq+tGFtQ3BXJVPjg5Z1iJKchpiJM5NxQidKv2/vAkNeR/d+ML3IO14 oHhMjnBSgG9aSCBKSbQvk76hYLIGxI/UzhyGymuXSCgTNzNYZSGfKyVlufro+ktKZP 7+JHU7Ktk6ejw== Subject: [PATCH v1 08/27] SUNRPC: Add @head and @tail variables in svcauth_gss_wrap_priv() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:14 -0500 Message-ID: <167319535402.7490.11914043108523808242.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Simplify the references to the head and tail iovecs for readability. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 573b9d029709..cfcd74e6369d 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1836,6 +1836,8 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) struct gss_svc_data *gsd = rqstp->rq_auth_data; struct rpc_gss_wire_cred *gc = &gsd->clcred; struct xdr_buf *buf = &rqstp->rq_res; + struct kvec *head = buf->head; + struct kvec *tail = buf->tail; u32 offset, pad, maj_stat; __be32 *p, *lenp; @@ -1844,7 +1846,7 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) return 0; lenp = p++; - offset = (u8 *)p - (u8 *)buf->head[0].iov_base; + offset = (u8 *)p - (u8 *)head->iov_base; *p++ = htonl(gc->gc_seq); /* XXX: Would be better to write some xdr helper functions for * nfs{2,3,4}xdr.c that place the data right, instead of copying: */ @@ -1856,19 +1858,17 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) * there is RPC_MAX_AUTH_SIZE slack space available in * both the head and tail. */ - if (buf->tail[0].iov_base) { - if (buf->tail[0].iov_base >= - buf->head[0].iov_base + PAGE_SIZE) + if (tail->iov_base) { + if (tail->iov_base >= head->iov_base + PAGE_SIZE) goto wrap_failed; - if (buf->tail[0].iov_base < buf->head[0].iov_base) + if (tail->iov_base < head->iov_base) goto wrap_failed; - if (buf->tail[0].iov_len + buf->head[0].iov_len + if (tail->iov_len + head->iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) goto wrap_failed; - memmove(buf->tail[0].iov_base + RPC_MAX_AUTH_SIZE, - buf->tail[0].iov_base, - buf->tail[0].iov_len); - buf->tail[0].iov_base += RPC_MAX_AUTH_SIZE; + memmove(tail->iov_base + RPC_MAX_AUTH_SIZE, tail->iov_base, + tail->iov_len); + tail->iov_base += RPC_MAX_AUTH_SIZE; } /* * If there is no current tail data, make sure there is @@ -1877,12 +1877,12 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) * is RPC_MAX_AUTH_SIZE slack space available in both the * head and tail. */ - if (!buf->tail[0].iov_base) { - if (buf->head[0].iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) + if (!tail->iov_base) { + if (head->iov_len + 2 * RPC_MAX_AUTH_SIZE > PAGE_SIZE) goto wrap_failed; - buf->tail[0].iov_base = buf->head[0].iov_base - + buf->head[0].iov_len + RPC_MAX_AUTH_SIZE; - buf->tail[0].iov_len = 0; + tail->iov_base = head->iov_base + + head->iov_len + RPC_MAX_AUTH_SIZE; + tail->iov_len = 0; } maj_stat = gss_wrap(gsd->rsci->mechctx, offset, buf, buf->pages); @@ -1891,9 +1891,9 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) *lenp = htonl(buf->len - offset); pad = 3 - ((buf->len - offset - 1) & 3); - p = (__be32 *)(buf->tail[0].iov_base + buf->tail[0].iov_len); + p = (__be32 *)(tail->iov_base + tail->iov_len); memset(p, 0, pad); - buf->tail[0].iov_len += pad; + tail->iov_len += pad; buf->len += pad; return 0; From patchwork Sun Jan 8 16:29:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092549 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 ABE64C53210 for ; Sun, 8 Jan 2023 16:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236096AbjAHQ30 (ORCPT ); Sun, 8 Jan 2023 11:29:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236107AbjAHQ3X (ORCPT ); Sun, 8 Jan 2023 11:29:23 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23EBD1E1 for ; Sun, 8 Jan 2023 08:29:22 -0800 (PST) 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 B3E7E60C8C for ; Sun, 8 Jan 2023 16:29:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F475C433D2 for ; Sun, 8 Jan 2023 16:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195361; bh=XJlX7SVbSFooarE6ZChy3YEAsu1nxHsHLQduCtUC/Z8=; h=Subject:From:To:Date:In-Reply-To:References:From; b=eTw67LBbpcQDXo1mBSahNQcY0jWDXsNjNlXNDg8I7UV3i6iWrQbFkJB/YSy1Fo5tS vlSEz4reGtja9IAk1yRXZTLxMSgZh4CArEKS6q+2VOGp4Uyn7IVeDh5/6hubn+rABq RPBmTwndujZ3oCtrSZADTMgZndI4oLRsYxCiNLpPBVRSXZtUDmIFYJlsjXBwEO7vms TEsJY6ex0yHvCyOjrT4Tmzt66jasuL+TBOd1JTG0loc+f2ZOX+AfI+AAOhoGNROpgR be2h8HoQzTurmkJZrPWrYdHLJuS7OtSvMyz6XRVaIn2PmuDORnDIiFe656Fl6PHJWj SSgEXJz78wVOQ== Subject: [PATCH v1 09/27] SUNRPC: Convert svcauth_gss_wrap_priv() to use xdr_stream() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:20 -0500 Message-ID: <167319536020.7490.3861780856965318259.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Actually xdr_stream does not add value here because of how gss_wrap() works. This is just a clean-up patch. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index cfcd74e6369d..6c49750c0f7a 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1830,6 +1830,11 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) * unsigned int seq_num; * proc_req_arg_t arg; * }; + * + * gss_wrap() expands the size of the RPC message payload in the + * response buffer. The main purpose of svcauth_gss_wrap_priv() + * is to ensure there is adequate space in the response buffer to + * avoid overflow during the wrap. */ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) { @@ -1847,9 +1852,9 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) lenp = p++; offset = (u8 *)p - (u8 *)head->iov_base; - *p++ = htonl(gc->gc_seq); - /* XXX: Would be better to write some xdr helper functions for - * nfs{2,3,4}xdr.c that place the data right, instead of copying: */ + /* Buffer space for this field has already been reserved + * in svcauth_gss_accept(). */ + *p = cpu_to_be32(gc->gc_seq); /* * If there is currently tail data, make sure there is @@ -1889,8 +1894,8 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) if (maj_stat != GSS_S_COMPLETE) goto bad_wrap; - *lenp = htonl(buf->len - offset); - pad = 3 - ((buf->len - offset - 1) & 3); + *lenp = cpu_to_be32(buf->len - offset); + pad = xdr_pad_size(buf->len - offset); p = (__be32 *)(tail->iov_base + tail->iov_len); memset(p, 0, pad); tail->iov_len += pad; From patchwork Sun Jan 8 16:29:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092550 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 346CAC54EBD for ; Sun, 8 Jan 2023 16:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234911AbjAHQ3h (ORCPT ); Sun, 8 Jan 2023 11:29:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236122AbjAHQ3c (ORCPT ); Sun, 8 Jan 2023 11:29:32 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07570E0B3 for ; Sun, 8 Jan 2023 08:29:29 -0800 (PST) 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 A6DB2B801C1 for ; Sun, 8 Jan 2023 16:29:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40FC9C433F0 for ; Sun, 8 Jan 2023 16:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195367; bh=EJf06XE3BIgFkfJUevBRppykrXg0S9c6ZdtJsFsdXys=; h=Subject:From:To:Date:In-Reply-To:References:From; b=VQCJiNZZpHG0TYx2KeppbOqgms5rmmFB/qTQfvjADCo8jvXpRDPMaAJPFJM1Jk93V 449ubQ4utZdhVUZ33sOcRa3PvDLqFp3nVWyzah0y/lq8idWkVn4WDyGsEjhxARkmPv T0swapudpKG341Kr0iH/oKPVS/3DRYXqiHHj+K2PkzWb60bjmueJJty4VdJjvW5OcG RkVyHxI56ac2rDnhyBg9N5DPU2opOc9wCif57/QZaEs7QirsrHG1SxO6IRnPES4Ten Mt1RtqqeigZ4pCi3ldaoxbFMDYqldjvlx/AjLRMQO4TLWZBkDpLCzp2tal7BmNSu4z F1X64rpNsU3tQ== Subject: [PATCH v1 10/27] SUNRPC: Check rq_auth_stat when preparing to wrap a response From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:26 -0500 Message-ID: <167319536633.7490.17297229100823594696.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Commit 5b304bc5bfcc ("[PATCH] knfsd: svcrpc: gss: fix failure on SVC_DENIED in integrity case") added a check to prevent wrapping an RPC response if reply_stat == MSG_DENIED, assuming that the only way to get to svcauth_gss_release() with that reply_stat value was if the reject_stat was AUTH_ERROR (reject_stat == MISMATCH is handled earlier in svc_process_common()). The code there is somewhat confusing. For one thing, rpc_success is an accept_stat value, not a reply_stat value. The correct reply_stat value to look for is RPC_MSG_DENIED. It happens to be the same value as rpc_success, so it all works out, but it's not terribly readable. Since commit 438623a06bac ("SUNRPC: Add svc_rqst::rq_auth_stat"), the actual auth_stat value is stored in the svc_rqst, so that value is now available to svcauth_gss_prepare_to_wrap() to make its decision to wrap, based on direct information about the authentication status of the RPC caller. No behavior change is intended, this simply replaces some old code with something that should be more self-documenting. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 6c49750c0f7a..71a147b0f90b 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1732,17 +1732,19 @@ svcauth_gss_accept(struct svc_rqst *rqstp) } static __be32 * -svcauth_gss_prepare_to_wrap(struct xdr_buf *resbuf, struct gss_svc_data *gsd) +svcauth_gss_prepare_to_wrap(struct svc_rqst *rqstp, struct gss_svc_data *gsd) { + struct xdr_buf *resbuf = &rqstp->rq_res; __be32 *p; u32 verf_len; p = gsd->verf_start; gsd->verf_start = NULL; - /* If the reply stat is nonzero, don't wrap: */ - if (*(p-1) != rpc_success) + /* AUTH_ERROR replies are not wrapped. */ + if (rqstp->rq_auth_stat != rpc_auth_ok) return NULL; + /* Skip the verifier: */ p += 1; verf_len = ntohl(*p++); @@ -1786,7 +1788,7 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) u32 offset, len, maj_stat; __be32 *p; - p = svcauth_gss_prepare_to_wrap(buf, gsd); + p = svcauth_gss_prepare_to_wrap(rqstp, gsd); if (p == NULL) goto out; @@ -1846,7 +1848,7 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) u32 offset, pad, maj_stat; __be32 *p, *lenp; - p = svcauth_gss_prepare_to_wrap(buf, gsd); + p = svcauth_gss_prepare_to_wrap(rqstp, gsd); if (p == NULL) return 0; From patchwork Sun Jan 8 16:29:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092551 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 244FCC53210 for ; Sun, 8 Jan 2023 16:29:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234916AbjAHQ3k (ORCPT ); Sun, 8 Jan 2023 11:29:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236098AbjAHQ3f (ORCPT ); Sun, 8 Jan 2023 11:29:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 873E360CD for ; Sun, 8 Jan 2023 08:29:34 -0800 (PST) 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 2283360C8C for ; Sun, 8 Jan 2023 16:29:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FA0EC433D2 for ; Sun, 8 Jan 2023 16:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195373; bh=+V1BJJF/5pa4hW5EKyheq6lEDttHVTrhXTIkOdLucdc=; h=Subject:From:To:Date:In-Reply-To:References:From; b=iNIleci4GrgMtudslV+cc2Uo2BFvLF6BwkFDHydBal1nCN1D1tMmhpe0EnxHqoy9R depCGfQq9FBbTTImmuPX3Ivb/pf/uZ6t2NrN666raerzPmUzI3rMxA76vgwlzExf6t fr1nmy9IXy3u2WBFq6MwxR+vQTXJrHJ+s0NK0lQpr57hUfpbc5OOa9/gbWAqVchTlm Ny9H1whI1ZtTNltPf/wlAXQA+xWttoKalv6VsuAn/LiDQeLUXn2TErJqXjHvdg9Qrh ROck351FnbCFv7hoews2ZheS1G8yEKJIk1AgFuqfQA3a1Diql2TfHYpV053iqN/r66 ZI0p7WRrR2giA== Subject: [PATCH v1 11/27] SUNRPC: Remove the rpc_stat variable in svc_process_common() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:32 -0500 Message-ID: <167319537254.7490.13683547890552781753.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever There's no RPC header field called rpc_stat; more precisely, the variable appears to be recording an accept_stat value. But it looks like we don't need to preserve this value at all, actually, so simply remove the variable. Signed-off-by: Chuck Lever --- net/sunrpc/svc.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 94f7efca60fc..489c5d1b67f9 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1232,12 +1232,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) struct svc_serv *serv = rqstp->rq_server; struct svc_process_info process; __be32 *p, *statp; - __be32 rpc_stat; int auth_res, rc; __be32 *reply_statp; - rpc_stat = rpc_success; - /* Will be turned off by GSS integrity and privacy services */ __set_bit(RQ_SPLICE_OK, &rqstp->rq_flags); /* Will be turned off only when NFSv4 Sessions are used */ @@ -1279,10 +1276,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) case SVC_OK: break; case SVC_GARBAGE: - goto err_garbage; + goto err_garbage_args; case SVC_SYSERR: - rpc_stat = rpc_system_err; - goto err_bad; + goto err_system_err; case SVC_DENIED: goto err_bad_auth; case SVC_CLOSE: @@ -1296,8 +1292,7 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) if (progp == NULL) goto err_bad_prog; - rpc_stat = progp->pg_init_request(rqstp, progp, &process); - switch (rpc_stat) { + switch (progp->pg_init_request(rqstp, progp, &process)) { case rpc_success: break; case rpc_prog_unavail: @@ -1408,13 +1403,16 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) svc_putnl(resv, RPC_PROC_UNAVAIL); goto sendit; -err_garbage: - svc_printk(rqstp, "failed to decode args\n"); +err_garbage_args: + svc_printk(rqstp, "failed to decode RPC header\n"); + + serv->sv_stats->rpcbadfmt++; + svc_putnl(resv, RPC_GARBAGE_ARGS); + goto sendit; - rpc_stat = rpc_garbage_args; -err_bad: +err_system_err: serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, ntohl(rpc_stat)); + svc_putnl(resv, RPC_SYSTEM_ERR); goto sendit; } From patchwork Sun Jan 8 16:29:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092552 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 B20E5C54EBD for ; Sun, 8 Jan 2023 16:29:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236114AbjAHQ3o (ORCPT ); Sun, 8 Jan 2023 11:29:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236098AbjAHQ3n (ORCPT ); Sun, 8 Jan 2023 11:29:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 572D55F64 for ; Sun, 8 Jan 2023 08:29:42 -0800 (PST) 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 16EC4B801C1 for ; Sun, 8 Jan 2023 16:29:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E2E2C433D2 for ; Sun, 8 Jan 2023 16:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195379; bh=6PAzxwEqD9ukhZNaFe3cyGdP9JoTNHBXO7Z6CLNET5c=; h=Subject:From:To:Date:In-Reply-To:References:From; b=r7RIxd2vU5DZrQcyy8sozkAJheFkY7+It4AvJLFkwS6c03ze14KtjxCJxnW1BX1QK UhhZcW9PYAOIbnypUiPRQETwRy9/WsO17yisdHOH1foTlL0vtoSPFuCeGnGtb2ULN2 gtBf/nu0TMRkZ77vYek5NrnuYxiIMIGxLw0rF+zzDA/2YZ7Lnf6o5DIsnaPfFbdsqu RGUXAaQtC189ogI6J/4esHMFnFrrFuN8pqpu+tZw/Ao26jcTFleVQC+OmCCeRbgITm FLKayHT4dHyonBknifQ5I4dXDt6HXiSdU0WvzDYxfIlIfsKdvmNfYDxA/W8zx0ArS2 t9E5qoBOkXLaQ== Subject: [PATCH v1 12/27] SUNRPC: Add XDR encoding helper for opaque_auth From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:38 -0500 Message-ID: <167319537874.7490.10030931409689592644.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever RFC 5531 defines an MSG_ACCEPTED Reply message like this: struct accepted_reply { opaque_auth verf; union switch (accept_stat stat) { case SUCCESS: ... In the current server code, struct opaque_auth encoding is open- coded. Introduce a helper that encodes an opaque_auth data item within the context of a xdr_stream. Done as part of hardening the server-side RPC header decoding and encoding paths. Signed-off-by: Chuck Lever --- include/linux/sunrpc/xdr.h | 2 ++ net/sunrpc/xdr.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index 884df67009f4..f3b6eb9accd7 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -348,6 +348,8 @@ ssize_t xdr_stream_decode_string_dup(struct xdr_stream *xdr, char **str, size_t maxlen, gfp_t gfp_flags); ssize_t xdr_stream_decode_opaque_auth(struct xdr_stream *xdr, u32 *flavor, void **body, unsigned int *body_len); +ssize_t xdr_stream_encode_opaque_auth(struct xdr_stream *xdr, u32 flavor, + void *body, unsigned int body_len); /** * xdr_align_size - Calculate padded size of an object diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index 56d87c784c9e..6b2ec24ec62d 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -2310,3 +2310,32 @@ ssize_t xdr_stream_decode_opaque_auth(struct xdr_stream *xdr, u32 *flavor, return len + ret; } EXPORT_SYMBOL_GPL(xdr_stream_decode_opaque_auth); + +/** + * xdr_stream_encode_opaque_auth - Encode struct opaque_auth (RFC5531 S8.2) + * @xdr: pointer to xdr_stream + * @flavor: verifier flavor to encode + * @body: content of body to encode + * @body_len: length of body to encode + * + * Return values: + * On success, returns length in bytes of XDR buffer consumed + * %-EBADMSG on XDR buffer overflow + * %-EMSGSIZE if the size of @body exceeds 400 octets + */ +ssize_t xdr_stream_encode_opaque_auth(struct xdr_stream *xdr, u32 flavor, + void *body, unsigned int body_len) +{ + ssize_t ret, len; + + if (unlikely(body_len > RPC_MAX_AUTH_SIZE)) + return -EMSGSIZE; + len = xdr_stream_encode_u32(xdr, flavor); + if (unlikely(len < 0)) + return len; + ret = xdr_stream_encode_opaque(xdr, body, body_len); + if (unlikely(ret < 0)) + return ret; + return len + ret; +} +EXPORT_SYMBOL_GPL(xdr_stream_encode_opaque_auth); From patchwork Sun Jan 8 16:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092553 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 36799C54EBD for ; Sun, 8 Jan 2023 16:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236103AbjAHQ3s (ORCPT ); Sun, 8 Jan 2023 11:29:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236101AbjAHQ3s (ORCPT ); Sun, 8 Jan 2023 11:29:48 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5AD0DEBD for ; Sun, 8 Jan 2023 08:29:46 -0800 (PST) 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 81C4060C58 for ; Sun, 8 Jan 2023 16:29:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D03DFC433EF for ; Sun, 8 Jan 2023 16:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195385; bh=gqNscWSrdJDd9bmr8rIMD/zIJ5K1IRNoU0wzTTcpUyE=; h=Subject:From:To:Date:In-Reply-To:References:From; b=dUbTWh+hxCn9jl+BfogtmHUioS+W0sr7JtFtwMIXGJB0N9VB0qGox2nWEzrJI/ayg bjh2FmfDHwqsCwcOgesZTyfgaUkHZjB3Dy6Ac3fePGvhWS8mzGMbkwzTX26uVGBxt7 iq1rkO3HiiwMdb+9pXxDCUsMYvhJaKIbZfAPMoxj/UwlOZm598DW3uLb2NUMji58tl 651ONRp5mWQ9avsyOBKHiwQrNrz0ThDsN9AuK9rf7sJlp1tmcQ81/JgxNbQi2uQuTh ag9REZ7jqxtHnYBEx59h3TWrjp8tV6xrD19XXnA7ZUyNIYcL+tkU/gU2L4iZWC0Tfb PRKipLbVfcCEQ== Subject: [PATCH v1 13/27] SUNRPC: Push svcxdr_init_encode() into svc_process_common() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:44 -0500 Message-ID: <167319538493.7490.10071921740622901364.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Now that all vs_dispatch functions invoke svcxdr_init_encode(), it is common code and can be pushed down into the generic RPC server. Signed-off-by: Chuck Lever --- fs/lockd/svc.c | 1 - fs/nfs/callback_xdr.c | 2 -- fs/nfsd/nfscache.c | 2 +- fs/nfsd/nfssvc.c | 6 ------ include/linux/sunrpc/xdr.h | 21 +++++++++++++++++++++ net/sunrpc/svc.c | 1 + 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c index e56d85335599..642e394e7a2d 100644 --- a/fs/lockd/svc.c +++ b/fs/lockd/svc.c @@ -704,7 +704,6 @@ static int nlmsvc_dispatch(struct svc_rqst *rqstp, __be32 *statp) if (*statp != rpc_success) return 1; - svcxdr_init_encode(rqstp); if (!procp->pc_encode(rqstp, &rqstp->rq_res_stream)) goto out_encode_err; diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c index 46d3f5986b4e..b4c3b7182198 100644 --- a/fs/nfs/callback_xdr.c +++ b/fs/nfs/callback_xdr.c @@ -984,8 +984,6 @@ nfs_callback_dispatch(struct svc_rqst *rqstp, __be32 *statp) { const struct svc_procedure *procp = rqstp->rq_procinfo; - svcxdr_init_encode(rqstp); - *statp = procp->pc_func(rqstp); return 1; } diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 3e64a3d50a1c..ef5ee548053b 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -488,7 +488,7 @@ int nfsd_cache_lookup(struct svc_rqst *rqstp) case RC_NOCACHE: break; case RC_REPLSTAT: - svc_putu32(&rqstp->rq_res.head[0], rp->c_replstat); + xdr_stream_encode_be32(&rqstp->rq_res_stream, rp->c_replstat); rtn = RC_REPLY; break; case RC_REPLBUFF: diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 1ed29eac80ed..dfa8ee6c04d5 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -1052,12 +1052,6 @@ int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) goto out_dropit; } - /* - * Need to grab the location to store the status, as - * NFSv4 does some encoding while processing - */ - svcxdr_init_encode(rqstp); - *statp = proc->pc_func(rqstp); if (test_bit(RQ_DROPME, &rqstp->rq_flags)) goto out_update_drop; diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index f3b6eb9accd7..72014c9216fc 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -474,6 +474,27 @@ xdr_stream_encode_u32(struct xdr_stream *xdr, __u32 n) return len; } +/** + * xdr_stream_encode_be32 - Encode a big-endian 32-bit integer + * @xdr: pointer to xdr_stream + * @n: integer to encode + * + * Return values: + * On success, returns length in bytes of XDR buffer consumed + * %-EMSGSIZE on XDR buffer overflow + */ +static inline ssize_t +xdr_stream_encode_be32(struct xdr_stream *xdr, __be32 n) +{ + const size_t len = sizeof(n); + __be32 *p = xdr_reserve_space(xdr, len); + + if (unlikely(!p)) + return -EMSGSIZE; + *p = n; + return len; +} + /** * xdr_stream_encode_u64 - Encode a 64-bit integer * @xdr: pointer to xdr_stream diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 489c5d1b67f9..1cdf68fda3f8 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1321,6 +1321,7 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) */ if (procp->pc_xdrressize) svc_reserve_auth(rqstp, procp->pc_xdrressize<<2); + svcxdr_init_encode(rqstp); /* Call the function that processes the request. */ rc = process.dispatch(rqstp, statp); From patchwork Sun Jan 8 16:29:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092554 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 8D798C53210 for ; Sun, 8 Jan 2023 16:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236101AbjAHQ3y (ORCPT ); Sun, 8 Jan 2023 11:29:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236098AbjAHQ3x (ORCPT ); Sun, 8 Jan 2023 11:29:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 152771E1 for ; Sun, 8 Jan 2023 08:29:53 -0800 (PST) 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 A317B60C8C for ; Sun, 8 Jan 2023 16:29:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1A6FC433EF for ; Sun, 8 Jan 2023 16:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195392; bh=Rvh99QF+FTkIBz73eDgIXWqlQdlPOHGsXOTisCDx47o=; h=Subject:From:To:Date:In-Reply-To:References:From; b=rH7JDHIhExTpPpwUDksm0AMhZEPH8eixp93b5LC/IJ2F6AsLbdqCX1ZqgxUOh7fBn VdWorKfNtVYa6Y+WeAZEojplMWQzIS0MQYQ1WwfhCaUQSdfkgOrE/escV/XJRek/XW d4ZbJSp+zT2ZBc+b6b9wB05h8TJHMPCFvKU0b/hC7CHANwb17u+9zCGgW3Jze6FNKD Cdbd1zW2+AjCYoOgDQjs5dwnb6qyj/ZeQqgx/f58EsV420c3BEVijHXq6HwJnGZoop y2rCtRvQ0lGlO0mao1cKEd4N3/IYis/OgNgRHCoXrRjmoftnFdmfN6RKmIY8D+IYY/ bfUJ2x+WL/pSQ== Subject: [PATCH v1 14/27] SUNRPC: Move svcxdr_init_encode() into ->accept methods From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:51 -0500 Message-ID: <167319539113.7490.9989691159064949552.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Refactor: So that the overhaul of each ->accept method can be done in separate smaller patches, temporarily move the svcxdr_init_encode() call into those methods. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 5 +++++ net/sunrpc/svc.c | 6 ++---- net/sunrpc/svcauth_unix.c | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 71a147b0f90b..759169baa52f 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1250,6 +1250,7 @@ svcauth_gss_legacy_init(struct svc_rqst *rqstp, goto out; ret = SVC_COMPLETE; + svcxdr_init_encode(rqstp); out: cache_put(&rsip->h, sn->rsi_cache); return ret; @@ -1378,6 +1379,7 @@ static int svcauth_gss_proxy_init(struct svc_rqst *rqstp, goto out; ret = SVC_COMPLETE; + svcxdr_init_encode(rqstp); out: gss_free_in_token_pages(&ud.in_token); gssp_free_upcall_data(&ud); @@ -1680,6 +1682,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp) rqstp->rq_auth_stat = rpc_autherr_badcred; switch (gc->gc_svc) { case RPC_GSS_SVC_NONE: + svcxdr_init_encode(rqstp); break; case RPC_GSS_SVC_INTEGRITY: /* placeholders for length and seq. number: */ @@ -1689,6 +1692,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp) rsci->mechctx)) goto garbage_args; rqstp->rq_auth_slack = RPC_MAX_AUTH_SIZE; + svcxdr_init_encode(rqstp); break; case RPC_GSS_SVC_PRIVACY: /* placeholders for length and seq. number: */ @@ -1698,6 +1702,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp) rsci->mechctx)) goto garbage_args; rqstp->rq_auth_slack = RPC_MAX_AUTH_SIZE * 2; + svcxdr_init_encode(rqstp); break; default: goto auth_err; diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 1cdf68fda3f8..9951311790bf 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1312,16 +1312,14 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) serv->sv_stats->rpccnt++; trace_svc_process(rqstp, progp->pg_name); - /* Build the reply header. */ - statp = resv->iov_base +resv->iov_len; - svc_putnl(resv, RPC_SUCCESS); + statp = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT); + *statp = rpc_success; /* un-reserve some of the out-queue now that we have a * better idea of reply size */ if (procp->pc_xdrressize) svc_reserve_auth(rqstp, procp->pc_xdrressize<<2); - svcxdr_init_encode(rqstp); /* Call the function that processes the request. */ rc = process.dispatch(rqstp, statp); diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index f09a148aa0c1..6281d23f98bf 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -778,6 +778,7 @@ svcauth_null_accept(struct svc_rqst *rqstp) svc_putnl(resv, 0); rqstp->rq_cred.cr_flavor = RPC_AUTH_NULL; + svcxdr_init_encode(rqstp); return SVC_OK; } @@ -865,6 +866,7 @@ svcauth_tls_accept(struct svc_rqst *rqstp) svc_putnl(resv, 0); rqstp->rq_cred.cr_flavor = RPC_AUTH_TLS; + svcxdr_init_encode(rqstp); return SVC_OK; } @@ -960,6 +962,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp) svc_putnl(resv, 0); rqstp->rq_cred.cr_flavor = RPC_AUTH_UNIX; + svcxdr_init_encode(rqstp); return SVC_OK; badcred: From patchwork Sun Jan 8 16:29:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092555 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 E0767C54EBD for ; Sun, 8 Jan 2023 16:30:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236098AbjAHQaC (ORCPT ); Sun, 8 Jan 2023 11:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236106AbjAHQaB (ORCPT ); Sun, 8 Jan 2023 11:30:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA4D13889 for ; Sun, 8 Jan 2023 08:30:00 -0800 (PST) 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 8214DB801C1 for ; Sun, 8 Jan 2023 16:29:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A8E9C433D2 for ; Sun, 8 Jan 2023 16:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195398; bh=T0t5gAk7FsIRyQ1OhhP35VCh7QUY/eTz7668FImmvtU=; h=Subject:From:To:Date:In-Reply-To:References:From; b=IVEnwOTkLRIHTyqBWaCh01OstZJsW1WzdspwOK40FlnmHcaJf3s/hsRf7SzMU0EyW XkfWMdv5ARN6vCEztrJ6Arf3k6BxJzDeVgcTHn8wOWyREb7la0ehrrSlZhIrvh9R6j 0OOGGzaPqGGyXXG6QvsWCwPlM8bgPVGVD1A3Y9F7kmZn0ptxvYM77femlcFpqLKGEr I9R6gIU8Xxza+Kk879AeyKCB8I4cbOyEV54cyIr0xOGcFSVi+rO3v8VtU0JN/mAx2S nhUEhN9p44A+4T3gPJydrDkqldWdvvl6/ZrV6ACqqkyjgz3DP2jQEnqf8xo6FCUCuG 9TnS/yEnwfv0w== Subject: [PATCH v1 15/27] SUNRPC: Use xdr_stream to encode Reply verifier in svcauth_null_accept() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:29:57 -0500 Message-ID: <167319539727.7490.8201680952185298779.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Done as part of hardening the server-side RPC header encoding path. Signed-off-by: Chuck Lever --- net/sunrpc/svcauth_unix.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 6281d23f98bf..b24d6c75588f 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -744,7 +744,6 @@ EXPORT_SYMBOL_GPL(svcauth_unix_set_client); static int svcauth_null_accept(struct svc_rqst *rqstp) { - struct kvec *resv = &rqstp->rq_res.head[0]; struct xdr_stream *xdr = &rqstp->rq_arg_stream; struct svc_cred *cred = &rqstp->rq_cred; u32 flavor, len; @@ -773,12 +772,12 @@ svcauth_null_accept(struct svc_rqst *rqstp) if (cred->cr_group_info == NULL) return SVC_CLOSE; /* kmalloc failure - client must retry */ - /* Put NULL verifier */ - svc_putnl(resv, RPC_AUTH_NULL); - svc_putnl(resv, 0); + svcxdr_init_encode(rqstp); + if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, + RPC_AUTH_NULL, NULL, 0) < 0) + return SVC_CLOSE; rqstp->rq_cred.cr_flavor = RPC_AUTH_NULL; - svcxdr_init_encode(rqstp); return SVC_OK; } From patchwork Sun Jan 8 16:30:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092556 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 D443DC54EBD for ; Sun, 8 Jan 2023 16:30:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233451AbjAHQaQ (ORCPT ); Sun, 8 Jan 2023 11:30:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236108AbjAHQaH (ORCPT ); Sun, 8 Jan 2023 11:30:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1856B3889 for ; Sun, 8 Jan 2023 08:30:07 -0800 (PST) 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 BF12FB801C1 for ; Sun, 8 Jan 2023 16:30:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D011C433D2 for ; Sun, 8 Jan 2023 16:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195404; bh=gvzRoP3m0yyKE9mvSvyx11q9Oms3Z4Vd15Er4glKHsA=; h=Subject:From:To:Date:In-Reply-To:References:From; b=qQOdhXTBxBKDMmsIo7iv9IG88w5MpieKeYQWVLyKWzQ+zLedfeRos9Ze5qYYQm7qq mwx8L/pHFPPISqZjQx+y0SCbamsEucKpgT2J2ZIuieE6VhgbKDzpOCi6JfV/4LZspH R/Ol7Pm8MLwGN3yb8D09lGL+FytKapfjYU2yYGxSK56Gy74IMuvMPgGgJ7haplagzM Gc3XzhlSP8lTcVDWkbozOJi8fCvtg0OcvGC8Uzk/8CPxcmysN56iUjAD2cxjkSLUhV RLUSxWFnJS/gwHp8q4MV3TVSVsYA/Fsc1RXxK+CUkHnxgYqMjzwhnrsUT9dG5gGUxi PTJWNX0/aMV7A== Subject: [PATCH v1 16/27] SUNRPC: Use xdr_stream to encode Reply verifier in svcauth_unix_accept() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:03 -0500 Message-ID: <167319540345.7490.5719470568781058899.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Done as part of hardening the server-side RPC header encoding path. Signed-off-by: Chuck Lever --- net/sunrpc/svcauth_unix.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index b24d6c75588f..e3981e124042 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -894,7 +894,6 @@ struct auth_ops svcauth_tls = { static int svcauth_unix_accept(struct svc_rqst *rqstp) { - struct kvec *resv = &rqstp->rq_res.head[0]; struct xdr_stream *xdr = &rqstp->rq_arg_stream; struct svc_cred *cred = &rqstp->rq_cred; struct user_namespace *userns; @@ -956,12 +955,12 @@ svcauth_unix_accept(struct svc_rqst *rqstp) return SVC_DENIED; } - /* Put NULL verifier */ - svc_putnl(resv, RPC_AUTH_NULL); - svc_putnl(resv, 0); + svcxdr_init_encode(rqstp); + if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, + RPC_AUTH_NULL, NULL, 0) < 0) + return SVC_CLOSE; rqstp->rq_cred.cr_flavor = RPC_AUTH_UNIX; - svcxdr_init_encode(rqstp); return SVC_OK; badcred: From patchwork Sun Jan 8 16:30:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092557 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 7B1AEC54EBE for ; Sun, 8 Jan 2023 16:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236108AbjAHQaR (ORCPT ); Sun, 8 Jan 2023 11:30:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236196AbjAHQaM (ORCPT ); Sun, 8 Jan 2023 11:30:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C7371E1 for ; Sun, 8 Jan 2023 08:30:11 -0800 (PST) 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 397B460C58 for ; Sun, 8 Jan 2023 16:30:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A16BC433EF for ; Sun, 8 Jan 2023 16:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195410; bh=hZN1FGfGFWv0uDeKk/7cYFtwpnzzfQgHp0lcODtUiYk=; h=Subject:From:To:Date:In-Reply-To:References:From; b=ehzwhOtmKrlkPppNS8NdTND2YGE7TX1c1HaqPy/+Cln+CH8Jnfn3Im7vYY6qqcWP8 rKLUF0nsRecI5R0MxG+GQ6A9qT7nsom29SgSQT/lL8rAqaQ3jpw/DdkxhTJLkkLYrI KXgWpm0eXfWsFsCC8gueifnKWcQc+jEdgTqDjk+xdMy1ouCeH8Hxanwit40IwBNime FuYRwf90xC0obS6fbr+NkQTQp5cEnhHv4d4nsFWCVFf036A8SYSX/L9Poe3zhYoaUR OpK9pecv0ILI7tb11XjdFZYeGzTjd5dcYmhrntYnqprXdusfpkJG0n1m4RKf4MVcwf 7PZBC1DUPJQZQ== Subject: [PATCH v1 17/27] SUNRPC: Use xdr_stream to encode Reply verifier in svcauth_tls_accept() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:09 -0500 Message-ID: <167319540967.7490.13888556503546252318.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Done as part of hardening the server-side RPC header encoding path. Signed-off-by: Chuck Lever --- net/sunrpc/svcauth_unix.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index e3981e124042..632150a6b947 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -822,9 +822,9 @@ svcauth_tls_accept(struct svc_rqst *rqstp) { struct xdr_stream *xdr = &rqstp->rq_arg_stream; struct svc_cred *cred = &rqstp->rq_cred; - struct kvec *resv = rqstp->rq_res.head; u32 flavor, len; void *body; + __be32 *p; /* Length of Call's credential body field: */ if (xdr_stream_decode_u32(xdr, &len) < 0) @@ -855,17 +855,21 @@ svcauth_tls_accept(struct svc_rqst *rqstp) if (cred->cr_group_info == NULL) return SVC_CLOSE; - /* Reply's verifier */ - svc_putnl(resv, RPC_AUTH_NULL); + svcxdr_init_encode(rqstp); if (rqstp->rq_xprt->xpt_ops->xpo_start_tls) { - svc_putnl(resv, 8); - memcpy(resv->iov_base + resv->iov_len, "STARTTLS", 8); - resv->iov_len += 8; - } else - svc_putnl(resv, 0); + p = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT * 2 + 8); + if (!p) + return SVC_CLOSE; + *p++ = rpc_auth_null; + *p++ = cpu_to_be32(8); + memcpy(p, "STARTTLS", 8); + } else { + if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, + RPC_AUTH_NULL, NULL, 0) < 0) + return SVC_CLOSE; + } rqstp->rq_cred.cr_flavor = RPC_AUTH_TLS; - svcxdr_init_encode(rqstp); return SVC_OK; } From patchwork Sun Jan 8 16:30:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092558 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 12C45C54EBD for ; Sun, 8 Jan 2023 16:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236163AbjAHQaY (ORCPT ); Sun, 8 Jan 2023 11:30:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236213AbjAHQaW (ORCPT ); Sun, 8 Jan 2023 11:30:22 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B20F3889 for ; Sun, 8 Jan 2023 08:30:19 -0800 (PST) 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 269E6B80B36 for ; Sun, 8 Jan 2023 16:30:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6F4FC433EF for ; Sun, 8 Jan 2023 16:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195416; bh=YHHvEm9US4fxdWSlhM2UIXg3vRA1UA9KlvMeKXgZ2Gw=; h=Subject:From:To:Date:In-Reply-To:References:From; b=VltanQz1/ItKScIKk2PcY39JxlRg+cJfYmzn+PVbZT/CgzCWmg74wdEFHZu285F9Q dZkwQQjt3LAOwwZdGHOq0w5O4cakjtOw9kKtEm1jCvJEDdVaN+NUL28X4UvixlFYv7 C3ZoYlScaNNETZDYMdEn3VOnwXQRARj+FC/bbgsyJZQ0RlULG8OK8uloICAmrRnTsB /oo+Z3mGS5quxAAEcVVlP0oG87eIcZ1DdRbPatcUGf/i9gtQDNAteFsmnUzxXno3e1 K9kHB98ey4/0sCZ2mKjMjPhxfj/23PaK+1WkEeirX1UWq3oUDAOclxobKPu1JpuUEC E0W49IBbkZ0Iw== Subject: [PATCH v1 18/27] SUNRPC: Convert unwrap data paths to use xdr_stream for replies From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:15 -0500 Message-ID: <167319541584.7490.2761785202452013247.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever We're now moving svcxdr_init_encode() to /before/ the flavor's ->accept method has set rq_auth_slack. Add a helper that can set rq_auth_slack /after/ svcxdr_init_encode() has been called. Signed-off-by: Chuck Lever --- include/linux/sunrpc/svc.h | 26 ++++++++++++++++++++++++-- net/sunrpc/auth_gss/svcauth_gss.c | 18 ++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index ed722dd33b46..dd9f68acd9f1 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -577,12 +577,34 @@ static inline void svcxdr_init_encode(struct svc_rqst *rqstp) xdr->buf = buf; xdr->iov = resv; xdr->p = resv->iov_base + resv->iov_len; - xdr->end = resv->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; + xdr->end = resv->iov_base + PAGE_SIZE; buf->len = resv->iov_len; xdr->page_ptr = buf->pages - 1; buf->buflen = PAGE_SIZE * (rqstp->rq_page_end - buf->pages); - buf->buflen -= rqstp->rq_auth_slack; xdr->rqst = NULL; } +/** + * svcxdr_set_auth_slack - + * @rqstp: RPC transaction + * @slack: buffer space to reserve for the transaction's security flavor + * + * Set the request's slack space requirement, and set aside that much + * space in the rqstp's rq_res.head for use when the auth wraps the Reply. + */ +static inline void svcxdr_set_auth_slack(struct svc_rqst *rqstp, int slack) +{ + struct xdr_stream *xdr = &rqstp->rq_res_stream; + struct xdr_buf *buf = &rqstp->rq_res; + struct kvec *resv = buf->head; + + rqstp->rq_auth_slack = slack; + + xdr->end -= XDR_QUADLEN(slack); + buf->buflen -= rqstp->rq_auth_slack; + + WARN_ON(xdr->iov != resv); + WARN_ON(xdr->p > xdr->end); +} + #endif /* SUNRPC_SVC_H */ diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 759169baa52f..fd1fd4143a8e 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1685,24 +1685,22 @@ svcauth_gss_accept(struct svc_rqst *rqstp) svcxdr_init_encode(rqstp); break; case RPC_GSS_SVC_INTEGRITY: - /* placeholders for length and seq. number: */ - svc_putnl(resv, 0); - svc_putnl(resv, 0); + svcxdr_init_encode(rqstp); + /* placeholders for body length and seq. number: */ + xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT * 2); if (svcauth_gss_unwrap_integ(rqstp, gc->gc_seq, rsci->mechctx)) goto garbage_args; - rqstp->rq_auth_slack = RPC_MAX_AUTH_SIZE; - svcxdr_init_encode(rqstp); + svcxdr_set_auth_slack(rqstp, RPC_MAX_AUTH_SIZE); break; case RPC_GSS_SVC_PRIVACY: - /* placeholders for length and seq. number: */ - svc_putnl(resv, 0); - svc_putnl(resv, 0); + svcxdr_init_encode(rqstp); + /* placeholders for body length and seq. number: */ + xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT * 2); if (svcauth_gss_unwrap_priv(rqstp, gc->gc_seq, rsci->mechctx)) goto garbage_args; - rqstp->rq_auth_slack = RPC_MAX_AUTH_SIZE * 2; - svcxdr_init_encode(rqstp); + svcxdr_set_auth_slack(rqstp, RPC_MAX_AUTH_SIZE * 2); break; default: goto auth_err; From patchwork Sun Jan 8 16:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092559 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 6CDD4C54EBE for ; Sun, 8 Jan 2023 16:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbjAHQas (ORCPT ); Sun, 8 Jan 2023 11:30:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236241AbjAHQaa (ORCPT ); Sun, 8 Jan 2023 11:30:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F542DF08 for ; Sun, 8 Jan 2023 08:30:25 -0800 (PST) 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 51A80B80B36 for ; Sun, 8 Jan 2023 16:30:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5C91C433F0 for ; Sun, 8 Jan 2023 16:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195423; bh=INNCOm/g3LiZmDobA6j++20wBCKNLNFkWa8CN7nJwCU=; h=Subject:From:To:Date:In-Reply-To:References:From; b=bDCg4joVhnQkLiTBIxkI5TLKjPz+y2rYJZIxCWW2ihQVwEfyZfxykKSwOcABpDwTW LwJB2WQsxlJfgGF9KLXC/S9uQanAIK+SwK9XjNGWNyP91awi/r+QajSnpF2Oy/Qve9 PD2bqKAEYZvNsK2xwfL1iGgaK73u/uAprPJpKXvM8WzOpypSKtmAalK7yQhPE8m1Ei EPQx5sVi4I8z7H59ak8mDRb+ltPojqTcGS2f+De4Vh/B9nkXHjKNGvm9eQMa3Zg6rB qvY2LyeOkAaG1nTB/FtSWqjcSLaiTrYCdWG0S/ko5PZ0EMJTwWz+r2SAHgMYgY7Dgq n0QYrOaq+7bFA== Subject: [PATCH v1 19/27] SUNRPC: Use xdr_stream to encode replies in server-side GSS upcall helpers From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:22 -0500 Message-ID: <167319542203.7490.329164343640966404.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever This code constructs replies to the decorated NULL procedure calls that establish GSS contexts. Convert this code path to use struct xdr_stream to encode such responses. Done as part of hardening the server-side RPC header encoding path. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 144 +++++++++++++++++++++++-------------- 1 file changed, 90 insertions(+), 54 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index fd1fd4143a8e..9f3633c42ebd 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -77,6 +77,7 @@ struct gss_svc_data { struct rsc *rsci; /* for temporary results */ + __be32 gsd_seq_num; u8 gsd_scratch[GSS_SCRATCH_SIZE]; }; @@ -771,20 +772,6 @@ svcauth_gss_verify_header(struct svc_rqst *rqstp, struct rsc *rsci, return SVC_OK; } -static int -gss_write_null_verf(struct svc_rqst *rqstp) -{ - __be32 *p; - - svc_putnl(rqstp->rq_res.head, RPC_AUTH_NULL); - p = rqstp->rq_res.head->iov_base + rqstp->rq_res.head->iov_len; - /* don't really need to check if head->iov_len > PAGE_SIZE ... */ - *p++ = 0; - if (!xdr_ressize_check(rqstp, p)) - return -1; - return 0; -} - static int gss_write_verf(struct svc_rqst *rqstp, struct gss_ctx *ctx_id, u32 seq) { @@ -821,6 +808,38 @@ gss_write_verf(struct svc_rqst *rqstp, struct gss_ctx *ctx_id, u32 seq) return err; } +/* + * Construct and encode a Reply's verifier field. The verifier's body + * field contains a variable-length checksum of the GSS sequence + * number. + */ +static bool +svcauth_gss_encode_verf(struct svc_rqst *rqstp, struct gss_ctx *ctx_id, u32 seq) +{ + struct gss_svc_data *gsd = rqstp->rq_auth_data; + u32 maj_stat; + struct xdr_buf verf_data; + struct xdr_netobj checksum; + struct kvec iov; + + gsd->gsd_seq_num = cpu_to_be32(seq); + iov.iov_base = &gsd->gsd_seq_num; + iov.iov_len = XDR_UNIT; + xdr_buf_from_iov(&iov, &verf_data); + + checksum.data = gsd->gsd_scratch; + maj_stat = gss_get_mic(ctx_id, &verf_data, &checksum); + if (maj_stat != GSS_S_COMPLETE) + goto bad_mic; + + return xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, RPC_AUTH_GSS, + checksum.data, checksum.len) > 0; + +bad_mic: + trace_rpcgss_svc_get_mic(rqstp, maj_stat); + return false; +} + struct gss_domain { struct auth_domain h; u32 pseudoflavor; @@ -1057,23 +1076,29 @@ svcauth_gss_set_client(struct svc_rqst *rqstp) return SVC_OK; } -static inline int -gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, - struct xdr_netobj *out_handle, int *major_status) +static bool +svcauth_gss_proc_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, + struct xdr_netobj *out_handle, int *major_status, + u32 seq_num) { + struct xdr_stream *xdr = &rqstp->rq_res_stream; struct rsc *rsci; - int rc; + bool rc; if (*major_status != GSS_S_COMPLETE) - return gss_write_null_verf(rqstp); + goto null_verifier; rsci = gss_svc_searchbyctx(cd, out_handle); if (rsci == NULL) { *major_status = GSS_S_NO_CONTEXT; - return gss_write_null_verf(rqstp); + goto null_verifier; } - rc = gss_write_verf(rqstp, rsci->mechctx, GSS_SEQ_WIN); + + rc = svcauth_gss_encode_verf(rqstp, rsci->mechctx, seq_num); cache_put(&rsci->h, cd); return rc; + +null_verifier: + return xdr_stream_encode_opaque_auth(xdr, RPC_AUTH_NULL, NULL, 0) > 0; } static void gss_free_in_token_pages(struct gssp_in_token *in_token) @@ -1163,24 +1188,35 @@ static int gss_read_proxy_verf(struct svc_rqst *rqstp, return SVC_DENIED; } -static inline int -gss_write_resv(struct kvec *resv, size_t size_limit, - struct xdr_netobj *out_handle, struct xdr_netobj *out_token, - int major_status, int minor_status) +/* + * RFC 2203, Section 5.2.3.1. + * + * struct rpc_gss_init_res { + * opaque handle<>; + * unsigned int gss_major; + * unsigned int gss_minor; + * unsigned int seq_window; + * opaque gss_token<>; + * }; + */ +static bool +svcxdr_encode_gss_init_res(struct xdr_stream *xdr, + struct xdr_netobj *handle, + struct xdr_netobj *gss_token, + unsigned int major_status, + unsigned int minor_status, u32 seq_num) { - if (resv->iov_len + 4 > size_limit) - return -1; - svc_putnl(resv, RPC_SUCCESS); - if (svc_safe_putnetobj(resv, out_handle)) - return -1; - if (resv->iov_len + 3 * 4 > size_limit) - return -1; - svc_putnl(resv, major_status); - svc_putnl(resv, minor_status); - svc_putnl(resv, GSS_SEQ_WIN); - if (svc_safe_putnetobj(resv, out_token)) - return -1; - return 0; + if (xdr_stream_encode_opaque(xdr, handle->data, handle->len) < 0) + return false; + if (xdr_stream_encode_u32(xdr, major_status) < 0) + return false; + if (xdr_stream_encode_u32(xdr, minor_status) < 0) + return false; + if (xdr_stream_encode_u32(xdr, seq_num) < 0) + return false; + if (xdr_stream_encode_opaque(xdr, gss_token->data, gss_token->len) < 0) + return false; + return true; } /* @@ -1195,7 +1231,6 @@ svcauth_gss_legacy_init(struct svc_rqst *rqstp, struct rpc_gss_wire_cred *gc) { struct xdr_stream *xdr = &rqstp->rq_arg_stream; - struct kvec *resv = &rqstp->rq_res.head[0]; struct rsi *rsip, rsikey; __be32 *p; u32 len; @@ -1240,17 +1275,17 @@ svcauth_gss_legacy_init(struct svc_rqst *rqstp, return SVC_CLOSE; ret = SVC_CLOSE; - /* Got an answer to the upcall; use it: */ - if (gss_write_init_verf(sn->rsc_cache, rqstp, - &rsip->out_handle, &rsip->major_status)) + if (!svcauth_gss_proc_init_verf(sn->rsc_cache, rqstp, &rsip->out_handle, + &rsip->major_status, GSS_SEQ_WIN)) + goto out; + if (xdr_stream_encode_u32(&rqstp->rq_res_stream, RPC_SUCCESS) < 0) goto out; - if (gss_write_resv(resv, PAGE_SIZE, - &rsip->out_handle, &rsip->out_token, - rsip->major_status, rsip->minor_status)) + if (!svcxdr_encode_gss_init_res(&rqstp->rq_res_stream, &rsip->out_handle, + &rsip->out_token, rsip->major_status, + rsip->minor_status, GSS_SEQ_WIN)) goto out; ret = SVC_COMPLETE; - svcxdr_init_encode(rqstp); out: cache_put(&rsip->h, sn->rsi_cache); return ret; @@ -1331,7 +1366,6 @@ static int gss_proxy_save_rsc(struct cache_detail *cd, static int svcauth_gss_proxy_init(struct svc_rqst *rqstp, struct rpc_gss_wire_cred *gc) { - struct kvec *resv = &rqstp->rq_res.head[0]; struct xdr_netobj cli_handle; struct gssp_upcall_data ud; uint64_t handle; @@ -1369,17 +1403,17 @@ static int svcauth_gss_proxy_init(struct svc_rqst *rqstp, goto out; } - /* Got an answer to the upcall; use it: */ - if (gss_write_init_verf(sn->rsc_cache, rqstp, - &cli_handle, &ud.major_status)) + if (!svcauth_gss_proc_init_verf(sn->rsc_cache, rqstp, &cli_handle, + &ud.major_status, GSS_SEQ_WIN)) + goto out; + if (xdr_stream_encode_u32(&rqstp->rq_res_stream, RPC_SUCCESS) < 0) goto out; - if (gss_write_resv(resv, PAGE_SIZE, - &cli_handle, &ud.out_token, - ud.major_status, ud.minor_status)) + if (!svcxdr_encode_gss_init_res(&rqstp->rq_res_stream, &cli_handle, + &ud.out_token, ud.major_status, + ud.minor_status, GSS_SEQ_WIN)) goto out; ret = SVC_COMPLETE; - svcxdr_init_encode(rqstp); out: gss_free_in_token_pages(&ud.in_token); gssp_free_upcall_data(&ud); @@ -1420,6 +1454,8 @@ svcauth_gss_proc_init(struct svc_rqst *rqstp, struct rpc_gss_wire_cred *gc) u32 flavor, len; void *body; + svcxdr_init_encode(rqstp); + /* Call's verf field: */ if (xdr_stream_decode_opaque_auth(xdr, &flavor, &body, &len) < 0) return SVC_GARBAGE; From patchwork Sun Jan 8 16:30:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092560 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 ED0E1C54EBD for ; Sun, 8 Jan 2023 16:30:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233340AbjAHQat (ORCPT ); Sun, 8 Jan 2023 11:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236283AbjAHQae (ORCPT ); Sun, 8 Jan 2023 11:30:34 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD26B3889 for ; Sun, 8 Jan 2023 08:30:31 -0800 (PST) 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 819A1B801C1 for ; Sun, 8 Jan 2023 16:30:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19594C433D2 for ; Sun, 8 Jan 2023 16:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195429; bh=ZQtoZtpcqBotzMxf+p0JnDbZAqwIG6/NqjwEfdrNiFk=; h=Subject:From:To:Date:In-Reply-To:References:From; b=oeHX1FGJYS6Xj55Xm+86rjJYTyHQvu3SBYOuHqssTB8fC/e31Ytc2B7Hk7gI1C6HK hAtziFrys2/e7ZTM5CI3hy0DApLwYmCtnE9CYREEt1fzN7nlzJ6tW77aVb9O7+RL6L ScTVtbqOXxPQiG3Jj19nDw6bch3ZSMMxY+Hcfwdefi95sp9qWieQ4pEHItujEasTuR yIIxJvD/ej1T8CtGPTdHo6R01dgU+Dp5c8HV/ecZkZOdVb68FcbCvTdAGAmI8krg1E vS3PEb5wBsukAao3QbCcjRTmgQN+o1nd6RTpd6p8QUZhzzt7R0CtFSwodn8+aB1eVH WOyTIDYbN3oAw== Subject: [PATCH v1 20/27] SUNRPC: Use xdr_stream for encoding GSS reply verifiers From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:28 -0500 Message-ID: <167319542822.7490.6255372906469543368.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Done as part of hardening the server-side RPC header encoding path. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 81 ++++--------------------------------- 1 file changed, 8 insertions(+), 73 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 9f3633c42ebd..89333669af26 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -693,28 +693,6 @@ static bool gss_check_seq_num(const struct svc_rqst *rqstp, struct rsc *rsci, goto out; } -static inline u32 round_up_to_quad(u32 i) -{ - return (i + 3 ) & ~3; -} - -static inline int -svc_safe_putnetobj(struct kvec *resv, struct xdr_netobj *o) -{ - u8 *p; - - if (resv->iov_len + 4 > PAGE_SIZE) - return -1; - svc_putnl(resv, o->len); - p = resv->iov_base + resv->iov_len; - resv->iov_len += round_up_to_quad(o->len); - if (resv->iov_len > PAGE_SIZE) - return -1; - memcpy(p, o->data, o->len); - memset(p + o->len, 0, round_up_to_quad(o->len) - o->len); - return 0; -} - /* * Decode and verify a Call's verifier field. For RPC_AUTH_GSS Calls, * the body of this field contains a variable length checksum. @@ -772,42 +750,6 @@ svcauth_gss_verify_header(struct svc_rqst *rqstp, struct rsc *rsci, return SVC_OK; } -static int -gss_write_verf(struct svc_rqst *rqstp, struct gss_ctx *ctx_id, u32 seq) -{ - __be32 *xdr_seq; - u32 maj_stat; - struct xdr_buf verf_data; - struct xdr_netobj mic; - __be32 *p; - struct kvec iov; - int err = -1; - - svc_putnl(rqstp->rq_res.head, RPC_AUTH_GSS); - xdr_seq = kmalloc(4, GFP_KERNEL); - if (!xdr_seq) - return -ENOMEM; - *xdr_seq = htonl(seq); - - iov.iov_base = xdr_seq; - iov.iov_len = 4; - xdr_buf_from_iov(&iov, &verf_data); - p = rqstp->rq_res.head->iov_base + rqstp->rq_res.head->iov_len; - mic.data = (u8 *)(p + 1); - maj_stat = gss_get_mic(ctx_id, &verf_data, &mic); - if (maj_stat != GSS_S_COMPLETE) - goto out; - *p++ = htonl(mic.len); - memset((u8 *)p + mic.len, 0, round_up_to_quad(mic.len) - mic.len); - p += XDR_QUADLEN(mic.len); - if (!xdr_ressize_check(rqstp, p)) - goto out; - err = 0; -out: - kfree(xdr_seq); - return err; -} - /* * Construct and encode a Reply's verifier field. The verifier's body * field contains a variable-length checksum of the GSS sequence @@ -1454,8 +1396,6 @@ svcauth_gss_proc_init(struct svc_rqst *rqstp, struct rpc_gss_wire_cred *gc) u32 flavor, len; void *body; - svcxdr_init_encode(rqstp); - /* Call's verf field: */ if (xdr_stream_decode_opaque_auth(xdr, &flavor, &body, &len) < 0) return SVC_GARBAGE; @@ -1642,15 +1582,15 @@ svcauth_gss_decode_credbody(struct xdr_stream *xdr, static int svcauth_gss_accept(struct svc_rqst *rqstp) { - struct kvec *resv = &rqstp->rq_res.head[0]; struct gss_svc_data *svcdata = rqstp->rq_auth_data; __be32 *rpcstart; struct rpc_gss_wire_cred *gc; struct rsc *rsci = NULL; - __be32 *reject_stat = resv->iov_base + resv->iov_len; int ret; struct sunrpc_net *sn = net_generic(SVC_NET(rqstp), sunrpc_net_id); + svcxdr_init_encode(rqstp); + rqstp->rq_auth_stat = rpc_autherr_badcred; if (!svcdata) svcdata = kmalloc(sizeof(*svcdata), GFP_KERNEL); @@ -1700,28 +1640,25 @@ svcauth_gss_accept(struct svc_rqst *rqstp) /* now act upon the command: */ switch (gc->gc_proc) { case RPC_GSS_PROC_DESTROY: - if (gss_write_verf(rqstp, rsci->mechctx, gc->gc_seq)) + if (!svcauth_gss_encode_verf(rqstp, rsci->mechctx, gc->gc_seq)) goto auth_err; /* Delete the entry from the cache_list and call cache_put */ sunrpc_cache_unhash(sn->rsc_cache, &rsci->h); - if (resv->iov_len + 4 > PAGE_SIZE) - goto drop; - svc_putnl(resv, RPC_SUCCESS); + if (xdr_stream_encode_u32(&rqstp->rq_res_stream, RPC_SUCCESS) < 0) + goto auth_err; goto complete; case RPC_GSS_PROC_DATA: rqstp->rq_auth_stat = rpcsec_gsserr_ctxproblem; - svcdata->verf_start = resv->iov_base + resv->iov_len; - if (gss_write_verf(rqstp, rsci->mechctx, gc->gc_seq)) + svcdata->verf_start = xdr_reserve_space(&rqstp->rq_res_stream, 0); + if (!svcauth_gss_encode_verf(rqstp, rsci->mechctx, gc->gc_seq)) goto auth_err; rqstp->rq_cred = rsci->cred; get_group_info(rsci->cred.cr_group_info); rqstp->rq_auth_stat = rpc_autherr_badcred; switch (gc->gc_svc) { case RPC_GSS_SVC_NONE: - svcxdr_init_encode(rqstp); break; case RPC_GSS_SVC_INTEGRITY: - svcxdr_init_encode(rqstp); /* placeholders for body length and seq. number: */ xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT * 2); if (svcauth_gss_unwrap_integ(rqstp, gc->gc_seq, @@ -1730,7 +1667,6 @@ svcauth_gss_accept(struct svc_rqst *rqstp) svcxdr_set_auth_slack(rqstp, RPC_MAX_AUTH_SIZE); break; case RPC_GSS_SVC_PRIVACY: - svcxdr_init_encode(rqstp); /* placeholders for body length and seq. number: */ xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT * 2); if (svcauth_gss_unwrap_priv(rqstp, gc->gc_seq, @@ -1755,8 +1691,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp) ret = SVC_GARBAGE; goto out; auth_err: - /* Restore write pointer to its original value: */ - xdr_ressize_check(rqstp, reject_stat); + xdr_truncate_encode(&rqstp->rq_res_stream, XDR_UNIT * 2); ret = SVC_DENIED; goto out; complete: From patchwork Sun Jan 8 16:30:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092561 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 45B56C53210 for ; Sun, 8 Jan 2023 16:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233542AbjAHQau (ORCPT ); Sun, 8 Jan 2023 11:30:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236195AbjAHQag (ORCPT ); Sun, 8 Jan 2023 11:30:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57075D10B for ; Sun, 8 Jan 2023 08:30:36 -0800 (PST) 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 E7BF260CA4 for ; Sun, 8 Jan 2023 16:30:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43BDDC433EF for ; Sun, 8 Jan 2023 16:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195435; bh=u9DYwf7CA8XuMgYmvtC4bPAvv6xzFBFcq7dZkbMKh+Y=; h=Subject:From:To:Date:In-Reply-To:References:From; b=og4WZce32B3pOD24Vc6X5cl41sw90C8EA1dM9rXq4jXKVmmAiTo7fwtE6zfELc3q4 o2OfxEzvWBDWkxWx4UYPy0TQ1UAgeyO5IHd1PeF8YKj6Ilf/hp+UJ9E9rO4euOdNr/ TwOs/gKKX+fXptFHMP5RYnj98/IbaMFZi7+qO9sDUDWOuxY/HgU8baHP+TkP1f68s9 wUvqwn3wrBuGnqv7MdllQ65fOgzkpMIg4qKh7YHHZHSTdA9nf514dQyflaq+J4p0Z7 NHco4eoNixDyRR0UALugbf/I0SPC7e5rPEK5JKP94y/1J0fc50tHrM59cAjIfqUzen VWa+H1aHC4uyw== Subject: [PATCH v1 21/27] SUNRPC: Hoist init_encode out of svc_authenticate() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:34 -0500 Message-ID: <167319543438.7490.15983256373144808077.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Now that each ->accept method has been converted, the svcxdr_init_encode() calls can be hoisted back up into the generic RPC server code. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 2 -- net/sunrpc/svc.c | 2 ++ net/sunrpc/svcauth_unix.c | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 89333669af26..560fb8a2803d 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1589,8 +1589,6 @@ svcauth_gss_accept(struct svc_rqst *rqstp) int ret; struct sunrpc_net *sn = net_generic(SVC_NET(rqstp), sunrpc_net_id); - svcxdr_init_encode(rqstp); - rqstp->rq_auth_stat = rpc_autherr_badcred; if (!svcdata) svcdata = kmalloc(sizeof(*svcdata), GFP_KERNEL); diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 9951311790bf..393eebd1f6fe 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1262,6 +1262,8 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) if (rqstp->rq_prog == progp->pg_prog) break; + svcxdr_init_encode(rqstp); + /* * Decode auth data, and add verifier to reply buffer. * We do this before anything else in order to get a decent diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 632150a6b947..b101700d155c 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -772,7 +772,6 @@ svcauth_null_accept(struct svc_rqst *rqstp) if (cred->cr_group_info == NULL) return SVC_CLOSE; /* kmalloc failure - client must retry */ - svcxdr_init_encode(rqstp); if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, RPC_AUTH_NULL, NULL, 0) < 0) return SVC_CLOSE; @@ -855,7 +854,6 @@ svcauth_tls_accept(struct svc_rqst *rqstp) if (cred->cr_group_info == NULL) return SVC_CLOSE; - svcxdr_init_encode(rqstp); if (rqstp->rq_xprt->xpt_ops->xpo_start_tls) { p = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT * 2 + 8); if (!p) @@ -959,7 +957,6 @@ svcauth_unix_accept(struct svc_rqst *rqstp) return SVC_DENIED; } - svcxdr_init_encode(rqstp); if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, RPC_AUTH_NULL, NULL, 0) < 0) return SVC_CLOSE; From patchwork Sun Jan 8 16:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092562 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 3DBF5C63797 for ; Sun, 8 Jan 2023 16:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236195AbjAHQax (ORCPT ); Sun, 8 Jan 2023 11:30:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236167AbjAHQan (ORCPT ); Sun, 8 Jan 2023 11:30:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A06A1E1 for ; Sun, 8 Jan 2023 08:30:42 -0800 (PST) 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 27DBA60CA4 for ; Sun, 8 Jan 2023 16:30:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 718AEC433F0 for ; Sun, 8 Jan 2023 16:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195441; bh=33QsprfYNWjDopL//M9suYmrYsCuunMToFxdGtLaWis=; h=Subject:From:To:Date:In-Reply-To:References:From; b=B8SHGToFDU6R6PyHGD9J2fMf2LHVDrADHfB+GR7RAv1de7ONZDGEM7BTg8wtYhRUw Hl/3qCAheiZilxwIsmzmAigmC8R0VnFc0pJuG4N8zhsjlVVtCEEwOFoP3ei1JYKcpI vh+jlCyqEFCe/5CeeXDvdijpcpKXFdTRCL/nC1UrtgWzKwQyWtUOQ8vVR/ByjhEbcn XKaAjjjYzbFVjXghLrPumDdYqIPuMLDqwlOF81IJuYAupiLP0tgTWcWEkH/mXfxni9 N4xkjy3yEaw6l9VyMQovBWC1mCF2ZZ1Y+uMJtFdUUiEdc5YAFs9I9t1hVo7XaJZLBz kwoYpCEhW8Qbw== Subject: [PATCH v1 22/27] SUNRPC: Convert RPC Reply header encoding to use xdr_stream From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:40 -0500 Message-ID: <167319544056.7490.15568010792301695670.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever The main part of RPC header encoding and the formation of error responses are now done using the xdr_stream helpers. Bounds checking before each XDR data item is encoded makes the server's encoding path safer against accidental buffer overflows. Signed-off-by: Chuck Lever --- net/sunrpc/svc.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 393eebd1f6fe..bcca1553c75a 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1227,13 +1227,14 @@ EXPORT_SYMBOL_GPL(svc_generic_init_request); static int svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) { + struct xdr_stream *xdr = &rqstp->rq_res_stream; struct svc_program *progp; const struct svc_procedure *procp = NULL; struct svc_serv *serv = rqstp->rq_server; struct svc_process_info process; __be32 *p, *statp; int auth_res, rc; - __be32 *reply_statp; + unsigned int aoffset; /* Will be turned off by GSS integrity and privacy services */ __set_bit(RQ_SPLICE_OK, &rqstp->rq_flags); @@ -1242,9 +1243,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) __clear_bit(RQ_DROPME, &rqstp->rq_flags); /* Construct the first words of the reply: */ - svc_putu32(resv, rqstp->rq_xid); - svc_putnl(resv, RPC_REPLY); - reply_statp = resv->iov_base + resv->iov_len; + svcxdr_init_encode(rqstp); + xdr_stream_encode_be32(xdr, rqstp->rq_xid); + xdr_stream_encode_be32(xdr, rpc_reply); p = xdr_inline_decode(&rqstp->rq_arg_stream, XDR_UNIT * 4); if (unlikely(!p)) @@ -1252,7 +1253,7 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) if (*p++ != cpu_to_be32(RPC_VERSION)) goto err_bad_rpc; - svc_putnl(resv, 0); /* ACCEPT */ + xdr_stream_encode_be32(xdr, rpc_msg_accepted); rqstp->rq_prog = be32_to_cpup(p++); rqstp->rq_vers = be32_to_cpup(p++); @@ -1262,8 +1263,6 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) if (rqstp->rq_prog == progp->pg_prog) break; - svcxdr_init_encode(rqstp); - /* * Decode auth data, and add verifier to reply buffer. * We do this before anything else in order to get a decent @@ -1314,6 +1313,7 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) serv->sv_stats->rpccnt++; trace_svc_process(rqstp, progp->pg_name); + aoffset = xdr_stream_pos(xdr); statp = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT); *statp = rpc_success; @@ -1332,9 +1332,8 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) if (rqstp->rq_auth_stat != rpc_auth_ok) goto err_bad_auth; - /* Check RPC status result */ if (*statp != rpc_success) - resv->iov_len = ((void*)statp) - resv->iov_base + 4; + xdr_truncate_encode(xdr, aoffset); if (procp->pc_encode == NULL) goto dropit; @@ -1364,27 +1363,28 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) err_bad_rpc: serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, 1); /* REJECT */ - svc_putnl(resv, 0); /* RPC_MISMATCH */ - svc_putnl(resv, 2); /* Only RPCv2 supported */ - svc_putnl(resv, 2); + xdr_stream_encode_u32(xdr, RPC_MSG_DENIED); + xdr_stream_encode_u32(xdr, RPC_MISMATCH); + /* Only RPCv2 supported */ + xdr_stream_encode_u32(xdr, RPC_VERSION); + xdr_stream_encode_u32(xdr, RPC_VERSION); goto sendit; err_bad_auth: dprintk("svc: authentication failed (%d)\n", be32_to_cpu(rqstp->rq_auth_stat)); serv->sv_stats->rpcbadauth++; - /* Restore write pointer to location of accept status: */ - xdr_ressize_check(rqstp, reply_statp); - svc_putnl(resv, 1); /* REJECT */ - svc_putnl(resv, 1); /* AUTH_ERROR */ - svc_putu32(resv, rqstp->rq_auth_stat); /* status */ + /* Restore write pointer to location of reply status: */ + xdr_truncate_encode(xdr, XDR_UNIT * 2); + xdr_stream_encode_u32(xdr, RPC_MSG_DENIED); + xdr_stream_encode_u32(xdr, RPC_AUTH_ERROR); + xdr_stream_encode_be32(xdr, rqstp->rq_auth_stat); goto sendit; err_bad_prog: dprintk("svc: unknown program %d\n", rqstp->rq_prog); serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, RPC_PROG_UNAVAIL); + xdr_stream_encode_u32(xdr, RPC_PROG_UNAVAIL); goto sendit; err_bad_vers: @@ -1392,28 +1392,28 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) rqstp->rq_vers, rqstp->rq_prog, progp->pg_name); serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, RPC_PROG_MISMATCH); - svc_putnl(resv, process.mismatch.lovers); - svc_putnl(resv, process.mismatch.hivers); + xdr_stream_encode_u32(xdr, RPC_PROG_MISMATCH); + xdr_stream_encode_u32(xdr, process.mismatch.lovers); + xdr_stream_encode_u32(xdr, process.mismatch.hivers); goto sendit; err_bad_proc: svc_printk(rqstp, "unknown procedure (%d)\n", rqstp->rq_proc); serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, RPC_PROC_UNAVAIL); + xdr_stream_encode_u32(xdr, RPC_PROC_UNAVAIL); goto sendit; err_garbage_args: svc_printk(rqstp, "failed to decode RPC header\n"); serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, RPC_GARBAGE_ARGS); + xdr_stream_encode_u32(xdr, RPC_GARBAGE_ARGS); goto sendit; err_system_err: serv->sv_stats->rpcbadfmt++; - svc_putnl(resv, RPC_SYSTEM_ERR); + xdr_stream_encode_u32(xdr, RPC_SYSTEM_ERR); goto sendit; } From patchwork Sun Jan 8 16:30:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092569 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 3F1BFC54EBD for ; Sun, 8 Jan 2023 16:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236384AbjAHQbU (ORCPT ); Sun, 8 Jan 2023 11:31:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236166AbjAHQau (ORCPT ); Sun, 8 Jan 2023 11:30:50 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFF10DEBE for ; Sun, 8 Jan 2023 08:30:48 -0800 (PST) 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 4D34360CF3 for ; Sun, 8 Jan 2023 16:30:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96FF8C433F0 for ; Sun, 8 Jan 2023 16:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195447; bh=HMfqoBN2jjsgLZC0cOfkE8Ao3mxgv26yjkwXo5i9NOs=; h=Subject:From:To:Date:In-Reply-To:References:From; b=RbTB+nz7n41LxdtNgZG3ppoS4oZ3hcBnpp0YdGbvrOXrW70/rX9EmhSyn1KwOThPj ahVW5lqdrru1PySgbc4dbzG/LoqkmkJdGcXPJNFRuvPpIB/LFfFjtMYkoa7XQNdL7y PRJpyooCYXEYYkaHkzC8HHWsQd0mKdP0xqmKnn/DLHNVaGBSsZJfJl36ykYRaDsgRl fEmhisM1cB03P2iBdlRXPfHJemU5Zsz0cn+Oc/jJLYOMvp/1zB6Cm9exfj/Qzu3tiz NAto0MIvI+OdPe94S50kQ7kMXFdBt5ApZx+Rlq4SQJBFp+RLMHJIX3T2D3KaSiRhmS /nMlcN7ICHIsA== Subject: [PATCH v1 23/27] SUNRPC: Final clean-up of svc_process_common() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:46 -0500 Message-ID: <167319544675.7490.2458325017024377410.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever The @resv parameter is no longer used. Signed-off-by: Chuck Lever --- net/sunrpc/svc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index bcca1553c75a..bb58915622ca 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1225,7 +1225,7 @@ EXPORT_SYMBOL_GPL(svc_generic_init_request); * Common routine for processing the RPC request. */ static int -svc_process_common(struct svc_rqst *rqstp, struct kvec *resv) +svc_process_common(struct svc_rqst *rqstp) { struct xdr_stream *xdr = &rqstp->rq_res_stream; struct svc_program *progp; @@ -1455,7 +1455,7 @@ svc_process(struct svc_rqst *rqstp) if (unlikely(*p != rpc_call)) goto out_baddir; - if (!svc_process_common(rqstp, resv)) + if (!svc_process_common(rqstp)) goto out_drop; return svc_send(rqstp); @@ -1478,7 +1478,6 @@ int bc_svc_process(struct svc_serv *serv, struct rpc_rqst *req, struct svc_rqst *rqstp) { - struct kvec *resv = &rqstp->rq_res.head[0]; struct rpc_task *task; int proc_error; int error; @@ -1509,22 +1508,21 @@ bc_svc_process(struct svc_serv *serv, struct rpc_rqst *req, rqstp->rq_arg.len = rqstp->rq_arg.head[0].iov_len + rqstp->rq_arg.page_len; - /* reset result send buffer "put" position */ - resv->iov_len = 0; - - svcxdr_init_decode(rqstp); + /* Reset the response buffer */ + rqstp->rq_res.head[0].iov_len = 0; /* * Skip the XID and calldir fields because they've already * been processed by the caller. */ + svcxdr_init_decode(rqstp); if (!xdr_inline_decode(&rqstp->rq_arg_stream, XDR_UNIT * 2)) { error = -EINVAL; goto out; } /* Parse and execute the bc call */ - proc_error = svc_process_common(rqstp, resv); + proc_error = svc_process_common(rqstp); atomic_dec(&req->rq_xprt->bc_slot_count); if (!proc_error) { From patchwork Sun Jan 8 16:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092570 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 63C5CC63797 for ; Sun, 8 Jan 2023 16:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233381AbjAHQbY (ORCPT ); Sun, 8 Jan 2023 11:31:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236238AbjAHQaz (ORCPT ); Sun, 8 Jan 2023 11:30:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFF33D125 for ; Sun, 8 Jan 2023 08:30:54 -0800 (PST) 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 692FE60C8C for ; Sun, 8 Jan 2023 16:30:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB683C433F0 for ; Sun, 8 Jan 2023 16:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195453; bh=4lC584jtj171PekqVOHcolTWrxY4SdAn+3yqCcCk0+g=; h=Subject:From:To:Date:In-Reply-To:References:From; b=g0edeSs0MTF5aU8hk0E+qpBs/6lL4yA0eQfrnLsF4pqqTVwTcHK8YRQnF9pTwCVfZ W6EDNL2l/2BgMHeFGHDnZEPogslgpVKPDseI4Zka1RGegjAvGHq0m+b/gMlnAepA62 caq6GWlkQ32awQZ5+ei+gHdUTLYiuZg1SgmuDzXYPRu5+JkzfOYwPMdI/7ysdIsmxK epd/u/vjq1hNgfhJfzR8qyfXy0JzJcZdp8AE+bIfhNdkxi0iyEWpcEQQiyv/mxWEyx R/N7r7Ax2hxOMJ24wtEzQPEMrHmZT2XaFGek6i2CHEI6EPFWBIBVO4gDw3+hd2lTaL s2JT+VajNP0LQ== Subject: [PATCH v1 24/27] SUNRPC: Remove no-longer-used helper functions From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:52 -0500 Message-ID: <167319545290.7490.4776771429759719974.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever The svc_get/put helpers are no longer used. Signed-off-by: Chuck Lever --- include/linux/sunrpc/svc.h | 66 +------------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index dd9f68acd9f1..32eb98e621c3 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -193,40 +193,6 @@ extern u32 svc_max_payload(const struct svc_rqst *rqstp); #define RPCSVC_MAXPAGES ((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE \ + 2 + 1) -static inline u32 svc_getnl(struct kvec *iov) -{ - __be32 val, *vp; - vp = iov->iov_base; - val = *vp++; - iov->iov_base = (void*)vp; - iov->iov_len -= sizeof(__be32); - return ntohl(val); -} - -static inline void svc_putnl(struct kvec *iov, u32 val) -{ - __be32 *vp = iov->iov_base + iov->iov_len; - *vp = htonl(val); - iov->iov_len += sizeof(__be32); -} - -static inline __be32 svc_getu32(struct kvec *iov) -{ - __be32 val, *vp; - vp = iov->iov_base; - val = *vp++; - iov->iov_base = (void*)vp; - iov->iov_len -= sizeof(__be32); - return val; -} - -static inline void svc_putu32(struct kvec *iov, __be32 val) -{ - __be32 *vp = iov->iov_base + iov->iov_len; - *vp = val; - iov->iov_len += sizeof(__be32); -} - /* * The context of a single thread, including the request currently being * processed. @@ -345,29 +311,6 @@ static inline struct sockaddr *svc_daddr(const struct svc_rqst *rqst) return (struct sockaddr *) &rqst->rq_daddr; } -/* - * Check buffer bounds after decoding arguments - */ -static inline int -xdr_argsize_check(struct svc_rqst *rqstp, __be32 *p) -{ - char *cp = (char *)p; - struct kvec *vec = &rqstp->rq_arg.head[0]; - return cp >= (char*)vec->iov_base - && cp <= (char*)vec->iov_base + vec->iov_len; -} - -static inline int -xdr_ressize_check(struct svc_rqst *rqstp, __be32 *p) -{ - struct kvec *vec = &rqstp->rq_res.head[0]; - char *cp = (char*)p; - - vec->iov_len = cp - (char*)vec->iov_base; - - return vec->iov_len <= PAGE_SIZE; -} - static inline void svc_free_res_pages(struct svc_rqst *rqstp) { while (rqstp->rq_next_page != rqstp->rq_respages) { @@ -540,9 +483,6 @@ static inline void svc_reserve_auth(struct svc_rqst *rqstp, int space) * svcxdr_init_decode - Prepare an xdr_stream for Call decoding * @rqstp: controlling server RPC transaction context * - * This function currently assumes the RPC header in rq_arg has - * already been decoded. Upon return, xdr->p points to the - * location of the upper layer header. */ static inline void svcxdr_init_decode(struct svc_rqst *rqstp) { @@ -550,11 +490,7 @@ static inline void svcxdr_init_decode(struct svc_rqst *rqstp) struct xdr_buf *buf = &rqstp->rq_arg; struct kvec *argv = buf->head; - /* - * svc_getnl() and friends do not keep the xdr_buf's ::len - * field up to date. Refresh that field before initializing - * the argument decoding stream. - */ + WARN_ON(buf->len != buf->head->iov_len + buf->page_len + buf->tail->iov_len); buf->len = buf->head->iov_len + buf->page_len + buf->tail->iov_len; xdr_init_decode(xdr, buf, argv->iov_base, NULL); From patchwork Sun Jan 8 16:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092573 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 53EB9C53210 for ; Sun, 8 Jan 2023 16:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236164AbjAHQbZ (ORCPT ); Sun, 8 Jan 2023 11:31:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236320AbjAHQbG (ORCPT ); Sun, 8 Jan 2023 11:31:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94FCD2708 for ; Sun, 8 Jan 2023 08:31:02 -0800 (PST) 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 4FC8DB801C1 for ; Sun, 8 Jan 2023 16:31:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E14CCC433D2 for ; Sun, 8 Jan 2023 16:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195460; bh=8TSO+zKjhsVabbyNtckRYRzcLooLsQtVJnH5HqPnLV4=; h=Subject:From:To:Date:In-Reply-To:References:From; b=jU/ynSLDPhV64E5/475BJkzRM63Bo/yU+2e+g6d71N6cE5OrhjERUL4v8nhVyUodq Ms8ttho7cv7xceuU+MRivxES151hmmIj8HVyX/EUAf9IPD8SW3ad/uEDTmsaIHau6J Kx1skCCvZ0Dm00uJ7/6tJ9kJIhuEESAIFeCMiGsRiA8/+bzaJyrsqZS2xuhGBmpLK+ Q/8tJ8+NCF5A4jRRJZFCVcOTOyCYci/i+IzAq6LHUbWmZ3q5/Y+dmr3evjuCcQlDpo 5jQtlGsR1Zi5Dt+kcwxSpINu/egPOFBU9hWXTtqH/ShdFHZS8moh5doWgF64G+1YXh JdkAi6YGjN0zQ== Subject: [PATCH v1 25/27] SUNRPC: Refactor RPC server dispatch method From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:30:59 -0500 Message-ID: <167319545904.7490.3650656071864510603.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Currently, svcauth_gss_accept() pre-reserves response buffer space for the RPC payload length and GSS sequence number before returning to the dispatcher, which then adds the header's accept_stat field. The problem is the accept_stat field is supposed to go before the length and seq_num fields. So svcauth_gss_release() has to relocate the accept_stat value (see svcauth_gss_prepare_to_wrap()). To enable these fields to be added to the response buffer in the correct (final) order, the pointer to the accept_stat has to be made available to svcauth_gss_accept() so that it can set it before reserving space for the length and seq_num fields. As a first step, move the pointer to the location of the accept_stat field into struct svc_rqst. Signed-off-by: Chuck Lever --- fs/lockd/svc.c | 4 ++-- fs/nfs/callback_xdr.c | 4 ++-- fs/nfsd/nfscache.c | 2 +- fs/nfsd/nfsd.h | 2 +- fs/nfsd/nfssvc.c | 4 ++-- include/linux/sunrpc/svc.h | 5 +++-- net/sunrpc/svc.c | 10 +++++----- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c index 642e394e7a2d..0b28a6cf9303 100644 --- a/fs/lockd/svc.c +++ b/fs/lockd/svc.c @@ -685,15 +685,15 @@ module_exit(exit_nlm); /** * nlmsvc_dispatch - Process an NLM Request * @rqstp: incoming request - * @statp: pointer to location of accept_stat field in RPC Reply buffer * * Return values: * %0: Processing complete; do not send a Reply * %1: Processing complete; send Reply in rqstp->rq_res */ -static int nlmsvc_dispatch(struct svc_rqst *rqstp, __be32 *statp) +static int nlmsvc_dispatch(struct svc_rqst *rqstp) { const struct svc_procedure *procp = rqstp->rq_procinfo; + __be32 *statp = rqstp->rq_accept_statp; if (!procp->pc_decode(rqstp, &rqstp->rq_arg_stream)) goto out_decode_err; diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c index b4c3b7182198..13b2af55497d 100644 --- a/fs/nfs/callback_xdr.c +++ b/fs/nfs/callback_xdr.c @@ -980,11 +980,11 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp) } static int -nfs_callback_dispatch(struct svc_rqst *rqstp, __be32 *statp) +nfs_callback_dispatch(struct svc_rqst *rqstp) { const struct svc_procedure *procp = rqstp->rq_procinfo; - *statp = procp->pc_func(rqstp); + *rqstp->rq_accept_statp = procp->pc_func(rqstp); return 1; } diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index ef5ee548053b..041faa13b852 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -509,7 +509,7 @@ int nfsd_cache_lookup(struct svc_rqst *rqstp) * nfsd_cache_update - Update an entry in the duplicate reply cache. * @rqstp: svc_rqst with a finished Reply * @cachetype: which cache to update - * @statp: Reply's status code + * @statp: pointer to Reply's NFS status code, or NULL * * This is called from nfsd_dispatch when the procedure has been * executed and the complete reply is in rqstp->rq_res. diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 93b42ef9ed91..a7de2ffe943b 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -86,7 +86,7 @@ bool nfssvc_encode_voidres(struct svc_rqst *rqstp, * Function prototypes. */ int nfsd_svc(int nrservs, struct net *net, const struct cred *cred); -int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp); +int nfsd_dispatch(struct svc_rqst *rqstp); int nfsd_nrthreads(struct net *); int nfsd_nrpools(struct net *); diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index dfa8ee6c04d5..ff10c46b62d3 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -1022,7 +1022,6 @@ nfsd(void *vrqstp) /** * nfsd_dispatch - Process an NFS or NFSACL Request * @rqstp: incoming request - * @statp: pointer to location of accept_stat field in RPC Reply buffer * * This RPC dispatcher integrates the NFS server's duplicate reply cache. * @@ -1030,9 +1029,10 @@ nfsd(void *vrqstp) * %0: Processing complete; do not send a Reply * %1: Processing complete; send Reply in rqstp->rq_res */ -int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) +int nfsd_dispatch(struct svc_rqst *rqstp) { const struct svc_procedure *proc = rqstp->rq_procinfo; + __be32 *statp = rqstp->rq_accept_statp; /* * Give the xdr decoder a chance to change this if it wants diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index 32eb98e621c3..f40a90ca5de6 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -251,6 +251,7 @@ struct svc_rqst { void * rq_argp; /* decoded arguments */ void * rq_resp; /* xdr'd results */ + __be32 *rq_accept_statp; void * rq_auth_data; /* flavor-specific data */ __be32 rq_auth_stat; /* authentication status */ int rq_auth_slack; /* extra space xdr code @@ -337,7 +338,7 @@ struct svc_deferred_req { struct svc_process_info { union { - int (*dispatch)(struct svc_rqst *, __be32 *); + int (*dispatch)(struct svc_rqst *rqstp); struct { unsigned int lovers; unsigned int hivers; @@ -389,7 +390,7 @@ struct svc_version { bool vs_need_cong_ctrl; /* Dispatch function */ - int (*vs_dispatch)(struct svc_rqst *, __be32 *); + int (*vs_dispatch)(struct svc_rqst *rqstp); }; /* diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index bb58915622ca..3c194e6f8f5e 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1232,9 +1232,9 @@ svc_process_common(struct svc_rqst *rqstp) const struct svc_procedure *procp = NULL; struct svc_serv *serv = rqstp->rq_server; struct svc_process_info process; - __be32 *p, *statp; int auth_res, rc; unsigned int aoffset; + __be32 *p; /* Will be turned off by GSS integrity and privacy services */ __set_bit(RQ_SPLICE_OK, &rqstp->rq_flags); @@ -1314,8 +1314,8 @@ svc_process_common(struct svc_rqst *rqstp) trace_svc_process(rqstp, progp->pg_name); aoffset = xdr_stream_pos(xdr); - statp = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT); - *statp = rpc_success; + rqstp->rq_accept_statp = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT); + *rqstp->rq_accept_statp = rpc_success; /* un-reserve some of the out-queue now that we have a * better idea of reply size @@ -1324,7 +1324,7 @@ svc_process_common(struct svc_rqst *rqstp) svc_reserve_auth(rqstp, procp->pc_xdrressize<<2); /* Call the function that processes the request. */ - rc = process.dispatch(rqstp, statp); + rc = process.dispatch(rqstp); if (procp->pc_release) procp->pc_release(rqstp); if (!rc) @@ -1332,7 +1332,7 @@ svc_process_common(struct svc_rqst *rqstp) if (rqstp->rq_auth_stat != rpc_auth_ok) goto err_bad_auth; - if (*statp != rpc_success) + if (*rqstp->rq_accept_statp != rpc_success) xdr_truncate_encode(xdr, aoffset); if (procp->pc_encode == NULL) From patchwork Sun Jan 8 16:31:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092572 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 80657C54EBE for ; Sun, 8 Jan 2023 16:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236166AbjAHQb0 (ORCPT ); Sun, 8 Jan 2023 11:31:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236336AbjAHQbI (ORCPT ); Sun, 8 Jan 2023 11:31:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34CA5DF55 for ; Sun, 8 Jan 2023 08:31:07 -0800 (PST) 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 C5F6E60C58 for ; Sun, 8 Jan 2023 16:31:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D584C433EF for ; Sun, 8 Jan 2023 16:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195466; bh=PxTLXEJNoYHcXloJXnqiHXoEapJ2V/lwU9gMk4LPwLw=; h=Subject:From:To:Date:In-Reply-To:References:From; b=bM8Y16JIQgaiklUOrM4XuSDpvJSuW9NMdxi51AL0jWBq/X0/enn1Dd9rtXEySi8+t uNZK3y2MuhhpQra+NFwPuDVIaYkp3bHLctrDi7o+bCcY37++74/cuwN/PI0xHIXl8C 9I7kgVkB1L4IkiagUXJuYUKHLeGxqTogxQ8koY7h5lgEQ11uj2WzaTRoxY5p4lD0oL iZ2ocbWbBc1QbQTsqcTiH3jxPxODnKQGuV2HrflMhv+40+hxDPH1hRLMJvdhzj/yqv z/0kx8pxu07EEODemPyEraXhavY1lx6Hwcx56CyuZE9Ok25Q/2kuOhBAd4nCYCCmFK G30AFgAP+iAEw== Subject: [PATCH v1 26/27] SUNRPC: Set rq_accept_statp inside ->accept methods From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:31:05 -0500 Message-ID: <167319546521.7490.43383592461162363.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever To navigate around the space that svcauth_gss_accept() reserves for the RPC payload body length and sequence number fields, svcauth_gss_release() does a little dance with the reply's accept_stat, moving the accept_stat value in the response buffer down by two words. Instead, let's have the ->accept() methods each set the proper final location of the accept_stat to avoid having to move things. Signed-off-by: Chuck Lever Reviewed-by: Jeff Layton --- include/linux/sunrpc/svc.h | 19 +++++++++++++++++++ net/sunrpc/auth_gss/svcauth_gss.c | 21 ++++++++++----------- net/sunrpc/svc.c | 2 -- net/sunrpc/svcauth_unix.c | 6 ++++++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index f40a90ca5de6..392d2d2620fa 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -544,4 +544,23 @@ static inline void svcxdr_set_auth_slack(struct svc_rqst *rqstp, int slack) WARN_ON(xdr->p > xdr->end); } +/** + * svcxdr_set_accept_stat - Reserve space for the accept_stat field + * @rqstp: RPC transaction context + * + * Return values: + * %true: Success + * %false: No response buffer space was available + */ +static inline bool svcxdr_set_accept_stat(struct svc_rqst *rqstp) +{ + struct xdr_stream *xdr = &rqstp->rq_res_stream; + + rqstp->rq_accept_statp = xdr_reserve_space(xdr, XDR_UNIT); + if (unlikely(!rqstp->rq_accept_statp)) + return false; + *rqstp->rq_accept_statp = rpc_success; + return true; +} + #endif /* SUNRPC_SVC_H */ diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 560fb8a2803d..333873abb7d9 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1220,7 +1220,7 @@ svcauth_gss_legacy_init(struct svc_rqst *rqstp, if (!svcauth_gss_proc_init_verf(sn->rsc_cache, rqstp, &rsip->out_handle, &rsip->major_status, GSS_SEQ_WIN)) goto out; - if (xdr_stream_encode_u32(&rqstp->rq_res_stream, RPC_SUCCESS) < 0) + if (!svcxdr_set_accept_stat(rqstp)) goto out; if (!svcxdr_encode_gss_init_res(&rqstp->rq_res_stream, &rsip->out_handle, &rsip->out_token, rsip->major_status, @@ -1348,7 +1348,7 @@ static int svcauth_gss_proxy_init(struct svc_rqst *rqstp, if (!svcauth_gss_proc_init_verf(sn->rsc_cache, rqstp, &cli_handle, &ud.major_status, GSS_SEQ_WIN)) goto out; - if (xdr_stream_encode_u32(&rqstp->rq_res_stream, RPC_SUCCESS) < 0) + if (!svcxdr_set_accept_stat(rqstp)) goto out; if (!svcxdr_encode_gss_init_res(&rqstp->rq_res_stream, &cli_handle, &ud.out_token, ud.major_status, @@ -1640,16 +1640,18 @@ svcauth_gss_accept(struct svc_rqst *rqstp) case RPC_GSS_PROC_DESTROY: if (!svcauth_gss_encode_verf(rqstp, rsci->mechctx, gc->gc_seq)) goto auth_err; + if (!svcxdr_set_accept_stat(rqstp)) + goto auth_err; /* Delete the entry from the cache_list and call cache_put */ sunrpc_cache_unhash(sn->rsc_cache, &rsci->h); - if (xdr_stream_encode_u32(&rqstp->rq_res_stream, RPC_SUCCESS) < 0) - goto auth_err; goto complete; case RPC_GSS_PROC_DATA: rqstp->rq_auth_stat = rpcsec_gsserr_ctxproblem; svcdata->verf_start = xdr_reserve_space(&rqstp->rq_res_stream, 0); if (!svcauth_gss_encode_verf(rqstp, rsci->mechctx, gc->gc_seq)) goto auth_err; + if (!svcxdr_set_accept_stat(rqstp)) + goto auth_err; rqstp->rq_cred = rsci->cred; get_group_info(rsci->cred.cr_group_info); rqstp->rq_auth_stat = rpc_autherr_badcred; @@ -1706,7 +1708,6 @@ svcauth_gss_accept(struct svc_rqst *rqstp) static __be32 * svcauth_gss_prepare_to_wrap(struct svc_rqst *rqstp, struct gss_svc_data *gsd) { - struct xdr_buf *resbuf = &rqstp->rq_res; __be32 *p; u32 verf_len; @@ -1721,13 +1722,11 @@ svcauth_gss_prepare_to_wrap(struct svc_rqst *rqstp, struct gss_svc_data *gsd) p += 1; verf_len = ntohl(*p++); p += XDR_QUADLEN(verf_len); - /* move accept_stat to right place: */ - memcpy(p, p + 2, 4); - /* Also don't wrap if the accept stat is nonzero: */ - if (*p != rpc_success) { - resbuf->head[0].iov_len -= 2 * 4; + + /* Also don't wrap if the accept_stat is nonzero: */ + if (*rqstp->rq_accept_statp != rpc_success) return NULL; - } + p++; return p; } diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 3c194e6f8f5e..c2ed8b06fadb 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1314,8 +1314,6 @@ svc_process_common(struct svc_rqst *rqstp) trace_svc_process(rqstp, progp->pg_name); aoffset = xdr_stream_pos(xdr); - rqstp->rq_accept_statp = xdr_reserve_space(&rqstp->rq_res_stream, XDR_UNIT); - *rqstp->rq_accept_statp = rpc_success; /* un-reserve some of the out-queue now that we have a * better idea of reply size diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index b101700d155c..62dfc8cdf8c5 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -775,6 +775,8 @@ svcauth_null_accept(struct svc_rqst *rqstp) if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, RPC_AUTH_NULL, NULL, 0) < 0) return SVC_CLOSE; + if (!svcxdr_set_accept_stat(rqstp)) + return SVC_CLOSE; rqstp->rq_cred.cr_flavor = RPC_AUTH_NULL; return SVC_OK; @@ -866,6 +868,8 @@ svcauth_tls_accept(struct svc_rqst *rqstp) RPC_AUTH_NULL, NULL, 0) < 0) return SVC_CLOSE; } + if (!svcxdr_set_accept_stat(rqstp)) + return SVC_CLOSE; rqstp->rq_cred.cr_flavor = RPC_AUTH_TLS; return SVC_OK; @@ -960,6 +964,8 @@ svcauth_unix_accept(struct svc_rqst *rqstp) if (xdr_stream_encode_opaque_auth(&rqstp->rq_res_stream, RPC_AUTH_NULL, NULL, 0) < 0) return SVC_CLOSE; + if (!svcxdr_set_accept_stat(rqstp)) + return SVC_CLOSE; rqstp->rq_cred.cr_flavor = RPC_AUTH_UNIX; return SVC_OK; From patchwork Sun Jan 8 16:31:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13092571 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 98086C67871 for ; Sun, 8 Jan 2023 16:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236196AbjAHQb0 (ORCPT ); Sun, 8 Jan 2023 11:31:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236374AbjAHQbO (ORCPT ); Sun, 8 Jan 2023 11:31:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 539EC1E1 for ; Sun, 8 Jan 2023 08:31:13 -0800 (PST) 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 E66F860C58 for ; Sun, 8 Jan 2023 16:31:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FA4AC433D2 for ; Sun, 8 Jan 2023 16:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673195472; bh=1Okx2EaUPDqe8bGyg9i0ooG9E8JUu6bNXgvChRG7idU=; h=Subject:From:To:Date:In-Reply-To:References:From; b=dox6VNg/u9wGnUBklBoO7WzzVfiYfNJgbg6FAL0vlW0VDKARP25qgWUqANHCsArSk FoiZEnVGs391ACZwxNpJUGja4LinMFbFLuDTVQjGg4/HOplE56e8qncJog2rMdFRO0 p3pmg96XY3i9cRA4ouo1fhbociHniPqGiW2SPWNIFpCQe7JRPZKa9WaKzmd5IDQUBd CGgs6I60iwiy/CdJvAT/6FEEZq8Shp67ffrNV8m8tuFVE7OnFaCeYMYq2ANlc7iZy8 PzUc7OomC3ISKZE5pVl9ocpdZe9L33zaGlc0H3sFzqULQZkeXwg7ckyZAiOBla+3KE EupAZUcGsrtUA== Subject: [PATCH v1 27/27] SUNRPC: Go back to using gsd->body_start From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Sun, 08 Jan 2023 11:31:11 -0500 Message-ID: <167319547140.7490.10549776139860828344.stgit@bazille.1015granger.net> In-Reply-To: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> References: <167319499150.7490.2294168831574653380.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Now that svcauth_gss_prepare_to_wrap() no longer computes the location of RPC header fields in the response buffer, svcauth_gss_accept() can save the location of the databody rather than the location of the verifier. Signed-off-by: Chuck Lever --- net/sunrpc/auth_gss/svcauth_gss.c | 78 +++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 333873abb7d9..419d5ad6311c 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -71,9 +71,7 @@ struct gss_svc_data { /* decoded gss client cred: */ struct rpc_gss_wire_cred clcred; - /* save a pointer to the beginning of the encoded verifier, - * for use in encryption/checksumming in svcauth_gss_release: */ - __be32 *verf_start; + u32 gsd_databody_offset; struct rsc *rsci; /* for temporary results */ @@ -1595,7 +1593,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp) if (!svcdata) goto auth_err; rqstp->rq_auth_data = svcdata; - svcdata->verf_start = NULL; + svcdata->gsd_databody_offset = 0; svcdata->rsci = NULL; gc = &svcdata->clcred; @@ -1647,11 +1645,11 @@ svcauth_gss_accept(struct svc_rqst *rqstp) goto complete; case RPC_GSS_PROC_DATA: rqstp->rq_auth_stat = rpcsec_gsserr_ctxproblem; - svcdata->verf_start = xdr_reserve_space(&rqstp->rq_res_stream, 0); if (!svcauth_gss_encode_verf(rqstp, rsci->mechctx, gc->gc_seq)) goto auth_err; if (!svcxdr_set_accept_stat(rqstp)) goto auth_err; + svcdata->gsd_databody_offset = xdr_stream_pos(&rqstp->rq_res_stream); rqstp->rq_cred = rsci->cred; get_group_info(rsci->cred.cr_group_info); rqstp->rq_auth_stat = rpc_autherr_badcred; @@ -1705,30 +1703,24 @@ svcauth_gss_accept(struct svc_rqst *rqstp) return ret; } -static __be32 * +static u32 svcauth_gss_prepare_to_wrap(struct svc_rqst *rqstp, struct gss_svc_data *gsd) { - __be32 *p; - u32 verf_len; + u32 offset; - p = gsd->verf_start; - gsd->verf_start = NULL; + /* Release can be called twice, but we only wrap once. */ + offset = gsd->gsd_databody_offset; + gsd->gsd_databody_offset = 0; /* AUTH_ERROR replies are not wrapped. */ if (rqstp->rq_auth_stat != rpc_auth_ok) - return NULL; - - /* Skip the verifier: */ - p += 1; - verf_len = ntohl(*p++); - p += XDR_QUADLEN(verf_len); + return 0; /* Also don't wrap if the accept_stat is nonzero: */ if (*rqstp->rq_accept_statp != rpc_success) - return NULL; + return 0; - p++; - return p; + return offset; } /* @@ -1756,21 +1748,21 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp) struct xdr_buf *buf = xdr->buf; struct xdr_buf databody_integ; struct xdr_netobj checksum; - u32 offset, len, maj_stat; - __be32 *p; + u32 offset, maj_stat; - p = svcauth_gss_prepare_to_wrap(rqstp, gsd); - if (p == NULL) + offset = svcauth_gss_prepare_to_wrap(rqstp, gsd); + if (!offset) goto out; - offset = (u8 *)(p + 1) - (u8 *)buf->head[0].iov_base; - len = buf->len - offset; - if (xdr_buf_subsegment(buf, &databody_integ, offset, len)) + if (xdr_buf_subsegment(buf, &databody_integ, offset + XDR_UNIT, + buf->len - offset - XDR_UNIT)) goto wrap_failed; /* Buffer space for these has already been reserved in * svcauth_gss_accept(). */ - *p++ = cpu_to_be32(len); - *p = cpu_to_be32(gc->gc_seq); + if (xdr_encode_word(buf, offset, databody_integ.len)) + goto wrap_failed; + if (xdr_encode_word(buf, offset + XDR_UNIT, gc->gc_seq)) + goto wrap_failed; checksum.data = gsd->gsd_scratch; maj_stat = gss_get_mic(gsd->rsci->mechctx, &databody_integ, &checksum); @@ -1817,17 +1809,19 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) struct kvec *head = buf->head; struct kvec *tail = buf->tail; u32 offset, pad, maj_stat; - __be32 *p, *lenp; + __be32 *p; - p = svcauth_gss_prepare_to_wrap(rqstp, gsd); - if (p == NULL) + offset = svcauth_gss_prepare_to_wrap(rqstp, gsd); + if (!offset) return 0; - lenp = p++; - offset = (u8 *)p - (u8 *)head->iov_base; - /* Buffer space for this field has already been reserved - * in svcauth_gss_accept(). */ - *p = cpu_to_be32(gc->gc_seq); + /* + * Buffer space for this field has already been reserved + * in svcauth_gss_accept(). Note that the GSS sequence + * number is encrypted along with the RPC reply payload. + */ + if (xdr_encode_word(buf, offset + XDR_UNIT, gc->gc_seq)) + goto wrap_failed; /* * If there is currently tail data, make sure there is @@ -1863,12 +1857,15 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp) tail->iov_len = 0; } - maj_stat = gss_wrap(gsd->rsci->mechctx, offset, buf, buf->pages); + maj_stat = gss_wrap(gsd->rsci->mechctx, offset + XDR_UNIT, buf, + buf->pages); if (maj_stat != GSS_S_COMPLETE) goto bad_wrap; - *lenp = cpu_to_be32(buf->len - offset); - pad = xdr_pad_size(buf->len - offset); + /* Wrapping can change the size of databody_priv. */ + if (xdr_encode_word(buf, offset, buf->len - offset - XDR_UNIT)) + goto wrap_failed; + pad = xdr_pad_size(buf->len - offset - XDR_UNIT); p = (__be32 *)(tail->iov_base + tail->iov_len); memset(p, 0, pad); tail->iov_len += pad; @@ -1908,9 +1905,6 @@ svcauth_gss_release(struct svc_rqst *rqstp) gc = &gsd->clcred; if (gc->gc_proc != RPC_GSS_PROC_DATA) goto out; - /* Release can be called twice, but we only wrap once. */ - if (gsd->verf_start == NULL) - goto out; switch (gc->gc_svc) { case RPC_GSS_SVC_NONE: