Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp342995pxb; Thu, 21 Jan 2021 08:23:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfmZoXMLQ/1c1ZpYUnNlDgRBmv/WDaDdxscnOa+bmJFbrXaKsx85kv61RhHBB9Tx518iV0 X-Received: by 2002:a05:6402:1155:: with SMTP id g21mr11864384edw.279.1611246220367; Thu, 21 Jan 2021 08:23:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611246220; cv=none; d=google.com; s=arc-20160816; b=fyzR8ACCcXHWsp3qTgKiMR1jdTZ69YG9TdN+trHUp5Kphl0c6MHpaCTJHcypMRjg/+ TaTDuoAVOitDKTmevnb1Q6zIJf+4OZvGxPKysyUQwc70yMBK4bJz3NMV6nBTOE+Gf/Kr Ci9zGofSKGHk0OurxHcvXKIXqriI7bXKIlnVhKYP8M3z9WbwCvpLimc7sjd1Yhnk/Pj+ WfT/BDVKf3KoWdBkDxVmIJgVSuvS1ihtL9kkkhAglzTSkLP2B8Id+kkSLNZ2vxsi5Qzk THHLpKFDvSfg4/jEuor0EdWmUnAqyCVaKiBD7VPtWb42icVMqqSy2BsZBTcbfaQ5iFg9 5lrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=EFzBAQ5BQ70mn43mGPGYaA23+DwQquRUhSseCUJP0+4=; b=tz8IziapQHCxRa3QaXz4/HpC9qQ7xEn8Kdpz/GF5DYZpAotV1QRquamDJa8Q9YlRFt RAfC29uYdoW2UFQ+0h6I7difZrMeiYDVSls0jPcElgfWdsUvmJyxjE4BVhy3EP6ilXzD LtFYkPFvXMnXmSrlOH1i8fo5QDrWOG84GL1TLLc65EI9RrojXxaujKhs80E8ohVmbriH enoEu/Of5wAQTBr6CUpuC6jGlQpFJg/T9LiwemMRIbinmMXJmbpILaBOO7TBuY+xyEcg 8PRSJwvjBReS/oR6BMx5s5CYUMqrL6QFlyzVR5ZK+EddUsrY5sx4Xz/oxCI3SZhyOA+r mYtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ea+iFd1o; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 16si2179911edw.253.2021.01.21.08.23.16; Thu, 21 Jan 2021 08:23:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ea+iFd1o; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732309AbhAUQWY (ORCPT + 99 others); Thu, 21 Jan 2021 11:22:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60172 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733007AbhAUQVt (ORCPT ); Thu, 21 Jan 2021 11:21:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611246023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=EFzBAQ5BQ70mn43mGPGYaA23+DwQquRUhSseCUJP0+4=; b=Ea+iFd1ogkinFyDJ0SCYjmrIAsNHIHKlL30JdSMMbeqL0q3TXsFlKw11auSzpz7j9Px/k+ dnvEQHkrxQt+cMB94JRNxK5Fa/FQ0vsgToDkaaFkr8v1YREcDMLUO6u+i8S5E079yqR6Ss afDzr5lHhbBb2jrpT6FWtbCfWI0WWw8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-95-wR-gAJcXPgyDENHVAZ5_Qg-1; Thu, 21 Jan 2021 11:20:20 -0500 X-MC-Unique: wR-gAJcXPgyDENHVAZ5_Qg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA9E8806662; Thu, 21 Jan 2021 16:20:19 +0000 (UTC) Received: from dwysocha.rdu.csb (ovpn-113-28.rdu2.redhat.com [10.10.113.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 419134C47C; Thu, 21 Jan 2021 16:20:19 +0000 (UTC) From: Dave Wysochanski To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 1/2] SUNRPC: Move simple_get_bytes and simple_get_netobj into xdr.h Date: Thu, 21 Jan 2021 11:20:15 -0500 Message-Id: <1611246016-21129-2-git-send-email-dwysocha@redhat.com> In-Reply-To: <1611246016-21129-1-git-send-email-dwysocha@redhat.com> References: <1611246016-21129-1-git-send-email-dwysocha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Remove duplicated helper functions to parse opaque XDR objects and place inside the xdr.h file. Also update comment which is wrong since lockd is not the only user of xdr_netobj. Signed-off-by: Dave Wysochanski --- include/linux/sunrpc/xdr.h | 33 +++++++++++++++++++++++++++++++-- net/sunrpc/auth_gss/auth_gss.c | 29 ----------------------------- net/sunrpc/auth_gss/gss_krb5_mech.c | 29 ----------------------------- 3 files changed, 31 insertions(+), 60 deletions(-) diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index 19b6dea27367..8ef788ff80b9 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -25,8 +25,7 @@ #define XDR_QUADLEN(l) (((l) + 3) >> 2) /* - * Generic opaque `network object.' At the kernel level, this type - * is used only by lockd. + * Generic opaque `network object.' */ #define XDR_MAX_NETOBJ 1024 struct xdr_netobj { @@ -34,6 +33,36 @@ struct xdr_netobj { u8 * data; }; +static inline const void * +simple_get_bytes(const void *p, const void *end, void *res, size_t len) +{ + const void *q = (const void *)((const char *)p + len); + if (unlikely(q > end || q < p)) + return ERR_PTR(-EFAULT); + memcpy(res, p, len); + return q; +} + +static inline const void * +simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) +{ + const void *q; + unsigned int len; + + p = simple_get_bytes(p, end, &len, sizeof(len)); + if (IS_ERR(p)) + return p; + q = (const void *)((const char *)p + len); + if (unlikely(q > end || q < p)) + return ERR_PTR(-EFAULT); + dest->data = kmemdup(p, len, GFP_NOFS); + if (unlikely(dest->data == NULL)) + return ERR_PTR(-ENOMEM); + dest->len = len; + return q; +} + + /* * Basic structure for transmission/reception of a client XDR message. * Features a header (for a linear buffer containing RPC headers diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c index 4ecc2a959567..228456b22b23 100644 --- a/net/sunrpc/auth_gss/auth_gss.c +++ b/net/sunrpc/auth_gss/auth_gss.c @@ -125,35 +125,6 @@ struct gss_auth { clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags); } -static const void * -simple_get_bytes(const void *p, const void *end, void *res, size_t len) -{ - const void *q = (const void *)((const char *)p + len); - if (unlikely(q > end || q < p)) - return ERR_PTR(-EFAULT); - memcpy(res, p, len); - return q; -} - -static inline const void * -simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) -{ - const void *q; - unsigned int len; - - p = simple_get_bytes(p, end, &len, sizeof(len)); - if (IS_ERR(p)) - return p; - q = (const void *)((const char *)p + len); - if (unlikely(q > end || q < p)) - return ERR_PTR(-EFAULT); - dest->data = kmemdup(p, len, GFP_NOFS); - if (unlikely(dest->data == NULL)) - return ERR_PTR(-ENOMEM); - dest->len = len; - return q; -} - static struct gss_cl_ctx * gss_cred_get_ctx(struct rpc_cred *cred) { diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c index ae9acf3a7389..99ea36d5eefe 100644 --- a/net/sunrpc/auth_gss/gss_krb5_mech.c +++ b/net/sunrpc/auth_gss/gss_krb5_mech.c @@ -143,35 +143,6 @@ return NULL; } -static const void * -simple_get_bytes(const void *p, const void *end, void *res, int len) -{ - const void *q = (const void *)((const char *)p + len); - if (unlikely(q > end || q < p)) - return ERR_PTR(-EFAULT); - memcpy(res, p, len); - return q; -} - -static const void * -simple_get_netobj(const void *p, const void *end, struct xdr_netobj *res) -{ - const void *q; - unsigned int len; - - p = simple_get_bytes(p, end, &len, sizeof(len)); - if (IS_ERR(p)) - return p; - q = (const void *)((const char *)p + len); - if (unlikely(q > end || q < p)) - return ERR_PTR(-EFAULT); - res->data = kmemdup(p, len, GFP_NOFS); - if (unlikely(res->data == NULL)) - return ERR_PTR(-ENOMEM); - res->len = len; - return q; -} - static inline const void * get_key(const void *p, const void *end, struct krb5_ctx *ctx, struct crypto_sync_skcipher **res) -- 1.8.3.1