Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3324926pxa; Tue, 25 Aug 2020 18:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdUGJNkxmV3lii6G1lfwsn5SFCAJeYBbDfCCJDP1UpBgksLLa+1Ydg6l2MScbdQPoIJyTb X-Received: by 2002:aa7:dc08:: with SMTP id b8mr4678189edu.271.1598406786023; Tue, 25 Aug 2020 18:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598406786; cv=none; d=google.com; s=arc-20160816; b=lB9au+jkXqLsMkJ0EOl0z3Jgp/kMDM84FjdyguO95k/8roxotJtI/IMmx/OvB43KLW Hv7nFtG/kzVNQf2uGrqGygUsxO+p+0sr6VJxJh9Sj3kyh1Xh27yPSL3CIFG0DcG7dvVm Ae46cGPWdzpPWE55cKEFLndnt01Gxuv/E9RUFz/813Utm+95+g5Awsd6XiLofPrr7edp lOCfKm0FBxUSHepEGo5KwU1qU9jbgRgWTe2YDCD06MBTJACsNA27IR7W9ovSKu90D7HZ VErNbqPd7yONAKdpbwZYE6JWowvGr/prSGHdAuN1mbfZZzsr/US9n4CjPjDw9z8SCyk5 srRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hqV9N4PnRzxhj1tk/i32inIsQ5DaM9n+01b3HzAWtM4=; b=GVTjFA4M2Vk24TopGy53zUfE2w8Zl3ULkl9DVTktSeW1U6mS1b4822JXYutEmLn31a 3ANn/xwz+bn3Ni+rKzdTOXyIE5TPTi2jlYzRZULDwCyQa+0rx6hgOFbAuaY7wRkKSwmU qe4GG5b3l9V2gXIX94vypxO3OUPT6wpKTiFGDDoOIQPSkHdSJzHq6fDr6/jyq0jjyrID 72mczCMq0ztsvh1dvP90g9CFkSSEEGrwTLJpGTatQrrlyHFerTd2xVjQbvxb+gy6nik/ fmTgdnmBY13PsRdh17QO3s5VZQALSoYttNfBfQcKg20B1481yzpDQVPmGb1Ch9CVLBit eYHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=G5SLKC1q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sa23si609767ejb.5.2020.08.25.18.52.43; Tue, 25 Aug 2020 18:53:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@arista.com header.s=googlenew header.b=G5SLKC1q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbgHZBut (ORCPT + 99 others); Tue, 25 Aug 2020 21:50:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgHZBtz (ORCPT ); Tue, 25 Aug 2020 21:49:55 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 114DFC061755 for ; Tue, 25 Aug 2020 18:49:55 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id 2so147983wrj.10 for ; Tue, 25 Aug 2020 18:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hqV9N4PnRzxhj1tk/i32inIsQ5DaM9n+01b3HzAWtM4=; b=G5SLKC1ql/dsc2y6ZL6itoWZCs1rqbPxKNYeTKPNOOSKUCymG+f0FM/tTKla3RsWu6 xbCvKYKcZEor5Dt2866Bqua5wnsNZj5cq/dbBaXYH2oJwt49zIg7Bl0OZK9GHV4vl4yT 67QKjIdjz4vBGLOirWo1SpfhcdYYIqrJl3z4OpRdqs+nCJbVDhbg1afekUT70kj1qbl7 kPTM1hhv6XR76pOHqilpvAMPr9yzNaF/MGsy8Gd/qLVb1g0Vk2kKgcDHQbreXkLbFcJQ /kv87Gi1w3ECzlIOJqlb9EcqgbMtTDMwjAE9Febr8sGR6xsfZjAejKucfT4O5baTjEOd mlDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hqV9N4PnRzxhj1tk/i32inIsQ5DaM9n+01b3HzAWtM4=; b=AEvkeamu0loyWCFfRiHM3D9nke0drpy3aUvFmHXskhLVn9cVdHbeqec7oLxUgoh+A4 t+IyDhuIVIggwiDYURARlRad43ML1Gw/uTCpJDmu8LhCXW+NsE3okz6JGyhGy7+a60PH pHCLazQgGnQk39nGctyPBEx5tG+XpnN23WH9By/Jev53Q4QAnoeekUqDTJeEovi6j1jl 0KYStN3PaFCVBZfqQLHHN468ER8iv1DMacx7Lpe+8ypTRaVpYmARkKheNuS2DNDcRO8+ WZpUhIf+y33mOgxLADvSzjeikGbmuCs4SFtUuGAgWETgLR6u19sRQKc4QEs5Ph83tS1p 10aw== X-Gm-Message-State: AOAM530equ9ble+/Up69c6aCs5hSfhcAtxTX30xcJ59scFaIYvqm0zgk C69imJkaCFlDF6tK1ubmZhb/pIM2Vmjgv8iRx5E= X-Received: by 2002:adf:b442:: with SMTP id v2mr4999276wrd.213.1598406593323; Tue, 25 Aug 2020 18:49:53 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:e84:2480:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id c10sm1263661wmk.30.2020.08.25.18.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 18:49:52 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , "David S. Miller" , Florian Westphal , Herbert Xu , Jakub Kicinski , Steffen Klassert , Stephen Suryaputra , netdev@vger.kernel.org Subject: [PATCH v2 2/6] xfrm/compat: Attach xfrm dumps to 64=>32 bit translator Date: Wed, 26 Aug 2020 02:49:45 +0100 Message-Id: <20200826014949.644441-3-dima@arista.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200826014949.644441-1-dima@arista.com> References: <20200826014949.644441-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org XFRM is disabled for compatible users because of the UABI difference. The difference is in structures paddings and in the result the size of netlink messages differ. Possibility for compatible application to manage xfrm tunnels was disabled by: the commmit 19d7df69fdb2 ("xfrm: Refuse to insert 32 bit userspace socket policies on 64 bit systems") and the commit 74005991b78a ("xfrm: Do not parse 32bits compiled xfrm netlink msg on 64bits host"). This is my second attempt to resolve the xfrm/compat problem by adding the 64=>32 and 32=>64 bit translators those non-visibly to a user provide translation between compatible user and kernel. Previous attempt was to interrupt the message ABI according to a syscall by xfrm_user, which resulted in over-complicated code [1]. Florian Westphal provided the idea of translator and some draft patches in the discussion. In these patches, his idea is reused and some of his initial code is also present. Currently nlmsg_unicast() is used by functions that dump structures that can be different in size for compat tasks, see dump_one_state() and dump_one_policy(). The following nlmsg_unicast() users exist today in xfrm: Function | Message can be different | in size on compat -------------------------------------------|------------------------------ xfrm_get_spdinfo() | N xfrm_get_sadinfo() | N xfrm_get_sa() | Y xfrm_alloc_userspi() | Y xfrm_get_policy() | Y xfrm_get_ae() | N Besides, dump_one_state() and dump_one_policy() can be used by filtered netlink dump for XFRM_MSG_GETSA, XFRM_MSG_GETPOLICY. Just as for xfrm multicast, allocate frag_list for compat skb journey down to recvmsg() which will give user the desired skb according to syscall bitness. [1]: https://lkml.kernel.org/r/20180726023144.31066-1-dima@arista.com Signed-off-by: Dmitry Safonov --- include/net/xfrm.h | 6 ++++++ net/xfrm/xfrm_compat.c | 10 ++++++++-- net/xfrm/xfrm_user.c | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 9810b5090338..9febf4f5d2ea 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -2002,12 +2002,18 @@ static inline int xfrm_tunnel_check(struct sk_buff *skb, struct xfrm_state *x, #ifdef CONFIG_XFRM_USER_COMPAT extern int xfrm_alloc_compat(struct sk_buff *skb); +extern int __xfrm_alloc_compat(struct sk_buff *skb, const struct nlmsghdr *nlh); extern const int xfrm_msg_min[XFRM_NR_MSGTYPES]; #else static inline int xfrm_alloc_compat(struct sk_buff *skb) { return 0; } +static inline int __xfrm_alloc_compat(struct sk_buff *skb, + const struct nlmsghdr *nlh) +{ + return 0; +} #endif #if IS_ENABLED(CONFIG_IPV6) diff --git a/net/xfrm/xfrm_compat.c b/net/xfrm/xfrm_compat.c index b9eb65dde0db..b34c8b56a571 100644 --- a/net/xfrm/xfrm_compat.c +++ b/net/xfrm/xfrm_compat.c @@ -272,9 +272,8 @@ static int xfrm_xlate64(struct sk_buff *dst, const struct nlmsghdr *nlh_src) return 0; } -int xfrm_alloc_compat(struct sk_buff *skb) +int __xfrm_alloc_compat(struct sk_buff *skb, const struct nlmsghdr *nlh_src) { - const struct nlmsghdr *nlh_src = nlmsg_hdr(skb); u16 type = nlh_src->nlmsg_type - XFRM_MSG_BASE; struct sk_buff *new = NULL; int err; @@ -300,3 +299,10 @@ int xfrm_alloc_compat(struct sk_buff *skb) return 0; } + +int xfrm_alloc_compat(struct sk_buff *skb) +{ + const struct nlmsghdr *nlh_src = nlmsg_hdr(skb); + + return __xfrm_alloc_compat(skb, nlh_src); +} diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 90c57d4a0b47..d135c6949336 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -992,6 +992,13 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr) return err; } nlmsg_end(skb, nlh); + + err = __xfrm_alloc_compat(skb, nlh); + if (err) { + nlmsg_cancel(skb, nlh); + return err; + } + return 0; } @@ -1365,6 +1372,12 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } + err = xfrm_alloc_compat(skb); + if (err) { + kfree_skb(resp_skb); + goto out; + } + err = nlmsg_unicast(net->xfrm.nlsk, resp_skb, NETLINK_CB(skb).portid); out: @@ -1795,6 +1808,13 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr return err; } nlmsg_end(skb, nlh); + + err = __xfrm_alloc_compat(skb, nlh); + if (err) { + nlmsg_cancel(skb, nlh); + return err; + } + return 0; } -- 2.27.0