From patchwork Thu Jul 26 02:31:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 949440 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=arista.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=arista.com header.i=@arista.com header.b="pB4lAQD8"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41bbkP6rXWz9ryl for ; Thu, 26 Jul 2018 12:33:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729047AbeGZDsE (ORCPT ); Wed, 25 Jul 2018 23:48:04 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:35897 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729072AbeGZDqb (ORCPT ); Wed, 25 Jul 2018 23:46:31 -0400 Received: by mail-ed1-f65.google.com with SMTP id k15-v6so341701edr.3 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=UdBjWQnLRNpYpXxh/8FdB0dOJUAJZhhXRxVIKhte+RHG5k3U4TQ4F2fVKGVzed1PkA fapXdjVPTiVLfieBqYaVquCssk91AAC3lnMHUkOriZLpQ9V7EEFERTS9tt8vmLAVLzdf R1f0hf0KbU3M5qDT2hgFUDuBH2o73Swj74t+yJb2yTdP11xI3Ex3xpnRBRCXIyHxm5Es uYzxEgpI106Dh9KekSuMY8L+b8jXntcyXDgmRd3yaH/sfLT15WUmWLG54diT9N9NSuWA CquZskv8sxMtKUdIT0c6fJ66YI5YbAiNXb8tDnVZ0mgIf6TSv3qLJyDawovJLUb2Cnp/ ob8w== X-Gm-Message-State: AOUpUlHHB6FS0ds4kvwunrJOWdRsYTg4zOT63AnEZaCQesaeDjrsL3PZ HfzX1IK15Uz5svL3UyC81xLqfw== X-Google-Smtp-Source: AAOMgpf7wx//fxDQb+4YI//gmBWpATU4VE6MZfgBy4fa5UlhK1Ymm2ZgSgU+2BBnzxFSDgfocdGRsw== 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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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) {