Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1472594imm; Wed, 25 Jul 2018 19:35:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcF/otY2lSljdHuvu3z1u5izUFrEIZCAyPcK8ipT48pafXS1Fjk1KWXzaRfIWC+3oCHWjtk X-Received: by 2002:a62:6cc7:: with SMTP id h190-v6mr101448pfc.113.1532572526004; Wed, 25 Jul 2018 19:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532572525; cv=none; d=google.com; s=arc-20160816; b=Z3ZHU+9TrFcccajUdo2zGrCsxzkNvFUVzRxcq3A4sVuYo5u8f2SESSowBc1xbEHFk5 jtF0bab+t8ip+goX/uR/e4VOA37zyD6503wpoutRPrAokHbMBBjrNaJzK8UZ8saEsMb4 jVCbz0WWExKRWHCOnlEYGCFkgoni+0WBfCBiuTmbn4EP4N2YTvYf/243XazY2pDqGVkY nXC/Ucl68GxPn1v207mVBq/U2k3lz0TrwAJi9F2i7vL2T1267kXmfUyWp8pbKtXWY2AF sdCv4J4nv/D0SK2/aC+sqYvz0ZkprLUISezi99MgdmbtDbxhi8XB9eP2Zow7hVBqXAwO LxUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=96codcclVJ7Yuq6KI06GJPty5De03p58ccgEKnN1XJ4=; b=pXXQgRmEnsWL07bcrX391W2rjg9drt+WxVRXFTxEXjCcJZYl8/fwP93tRWIKVq9aK1 gahUuOKSFm/fFmd9CoGFF3LCWSYHciVevKWwwFz+tJiIczzaT7Ye3UfPZ5KnAirlVlSt gNSLVpw8nPkaeuoG9PGuZwFR4uoyuNOT6CwyGQANhmXS6XJXOAMnTl/CdizETM6CQRTp DakL7f3kPcTlVTqPuag95uyVPvquQ+IRrgirgmjgtlUHAtLZU8+mgF+2PF3JNGRZkGux ecQGBFyeqXIvuf6NP4WV4EI1fJCOwU7MTXZp6PBWS94ctdJOe1yduetuegPNWPSBg9/j /mzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=pB4lAQD8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si132392pgb.399.2018.07.25.19.35.11; Wed, 25 Jul 2018 19:35:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=pB4lAQD8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1730233AbeGZDrz (ORCPT + 99 others); Wed, 25 Jul 2018 23:47:55 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:46485 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729073AbeGZDqc (ORCPT ); Wed, 25 Jul 2018 23:46:32 -0400 Received: by mail-ed1-f68.google.com with SMTP id o8-v6so324079edt.13 for ; Wed, 25 Jul 2018 19:31:58 -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; bh=96codcclVJ7Yuq6KI06GJPty5De03p58ccgEKnN1XJ4=; b=pB4lAQD8JA52RQDlbyrz8G/lQpgXxOqiRByZKMh4bcudH47VT/QGXAIT19/EudhpfT gOIGxY6gvszT5pq+r8LsOH78/mv2c4uXHceMInMcixVajDSUkd4LUHVR+42DmyiqZlie +kLCeLd8Bw30aVJtDYrM5j6Qg9S2bmHN6L37PcS5+ck782wqJymFtoFPRVInw1qzwCl7 vAWZ3jGactZhFAO0ugquyunEsTBsFh8mpGxJERwyu8L/fHd81ge76xR5ESw+9ikuAuFK bnJi694SmqJqiDCer/+OvpVRv6iZkMJFaWG0ulfKfTkZwhZLT7/ZENNa5Cpu0nNjQ2Oy hObg== 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; bh=96codcclVJ7Yuq6KI06GJPty5De03p58ccgEKnN1XJ4=; b=BYCHaQ2MmQxZq7Mm0A9AraVqwJCy45HHHOVacDM8OfP9/BVgSxXtT7Po9QiY+pwMVH 818EHyGHW8VUfMtf5D3KGKYvHUSXSvjEem4VhapPr97SBcJgfVv+rbuBPV1bmBZlSdVH E27CJInMAw2eFjrZZ1DDsIbV/TEcIVv4RXoNgmUfDEMjIyPxkFGjDQYYy5Z2qP7rrZMK 9k0QBUWYmFB4aIN5cgIyHZX++FwbuowYoKxd2QZjU4UEdBrX4jehUbM9vyoaAE5UTlLm Fg2dog/uTmbHFV/ipuOsNCpzAlJ9qIirJKv5f037IOjyMBpqt3+QEMCg1Rcaszafkhnn lfrQ== X-Gm-Message-State: AOUpUlEeQMEqdp2iDeybxCFkBuYdKdGGWnZI5PFoKFwLFMwM5x7sXewc 461S4fJ88RoI6mszoXV6/VCwj6B9qYc= X-Received: by 2002:a50:a347:: with SMTP id 65-v6mr480252edn.299.1532572317784; Wed, 25 Jul 2018 19:31:57 -0700 (PDT) Received: from dhcp.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id x13-v6sm241024edx.17.2018.07.25.19.31.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Jul 2018 19:31:57 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov , "David S. Miller" , Herbert Xu , Steffen Klassert , Dmitry Safonov <0x7f454c46@gmail.com>, netdev@vger.kernel.org Subject: [PATCH 10/18] xfrm: Send state notifications in compat format too Date: Thu, 26 Jul 2018 03:31:36 +0100 Message-Id: <20180726023144.31066-11-dima@arista.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180726023144.31066-1-dima@arista.com> References: <20180726023144.31066-1-dima@arista.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Applications that used native bind() syscall are in XFRMNLGRP_SA, so send there xfrm_usersa_info messages (with 64-bit ABI). Compatible applications are added to kernel-hidden XFRMNLGRP_COMPAT_SA group, so send there xfrm_usersa_info messages_packed (with 32-bit ABI) Cc: "David S. Miller" Cc: Herbert Xu Cc: Steffen Klassert Cc: netdev@vger.kernel.org Signed-off-by: Dmitry Safonov --- net/xfrm/xfrm_user.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 63622264a3a9..230462077dc9 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -2856,18 +2856,24 @@ static inline unsigned int xfrm_sa_len(struct xfrm_state *x) return l; } -static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) +static int __xfrm_notify_sa(struct xfrm_state *x, + const struct km_event *c, bool compat) { struct net *net = xs_net(x); - struct xfrm_usersa_info *p; struct xfrm_usersa_id *id; struct nlmsghdr *nlh; struct sk_buff *skb; unsigned int len = xfrm_sa_len(x); - unsigned int headlen; + unsigned int headlen, usersa_info_size; + void *usersa_info; int err; - headlen = sizeof(*p); + if (compat) + usersa_info_size = sizeof(struct xfrm_usersa_info_packed); + else + usersa_info_size = sizeof(struct xfrm_usersa_info); + headlen = usersa_info_size; + if (c->event == XFRM_MSG_DELSA) { len += nla_total_size(headlen); headlen = sizeof(*id); @@ -2884,7 +2890,7 @@ static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) if (nlh == NULL) goto out_free_skb; - p = nlmsg_data(nlh); + usersa_info = nlmsg_data(nlh); if (c->event == XFRM_MSG_DELSA) { struct nlattr *attr; @@ -2895,26 +2901,40 @@ static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) id->family = x->props.family; id->proto = x->id.proto; - attr = nla_reserve(skb, XFRMA_SA, sizeof(*p)); + attr = nla_reserve(skb, XFRMA_SA, usersa_info_size); err = -EMSGSIZE; if (attr == NULL) goto out_free_skb; - p = nla_data(attr); + usersa_info = nla_data(attr); } - err = copy_to_user_state_extra(x, p, skb); + + if (compat) + err = copy_to_user_state_extra(x, usersa_info, skb); + else + err = copy_to_user_state_extra_compat(x, usersa_info, skb); if (err) goto out_free_skb; nlmsg_end(skb, nlh); - return xfrm_nlmsg_multicast(net, skb, 0, XFRMNLGRP_SA); + return xfrm_nlmsg_multicast(net, skb, 0, + compat ? XFRMNLGRP_COMPAT_SA : XFRMNLGRP_SA); out_free_skb: kfree_skb(skb); return err; } +static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) +{ + int ret = __xfrm_notify_sa(x, c, false); + + if ((ret && ret != -ESRCH) || !IS_ENABLED(CONFIG_COMPAT)) + return ret; + return __xfrm_notify_sa(x, c, true); +} + static int xfrm_send_state_notify(struct xfrm_state *x, const struct km_event *c) { -- 2.13.6