Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1472069imm; Wed, 25 Jul 2018 19:34:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc5evweiuQ68G/T30Ibk8cFV5cK6t9OQ8X+WSKkq/CQkxIEK4eQ54fKs5LNmLsJ1Mc4Ds9P X-Received: by 2002:a65:5cc5:: with SMTP id b5-v6mr70020pgt.425.1532572485448; Wed, 25 Jul 2018 19:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532572485; cv=none; d=google.com; s=arc-20160816; b=ZsCeG1WgsrgYm+qeiYvCgbsYb9j06Nc4PH5iVk1o/GGesWeJfSZdQb7JKfLTKctxxA 3sj8uty730dR9zUdBCem6NEsl1fX7yngJR/klIc3ox3xlnWJy+pCMT5d5tvLco0eV4Dq 7Q2HFcvRUe5KgRN/UsbXSwpbwb3tpMZTwxd8aUCM+r2U8jArmnNC9354vI99RBTDqF0w IRrTKoC4Bm9NTb0OLB0BgSF3Ov6UEOzksxg8+rLEOR7k324/eOR+MSptsdy5XMY00saP Xscl4D4MA+mFC81Y/6bgQlQl9uZ19mMa6jZdNUjprBUdfIBsJTOi4tH8AxCuBg/Aj0qP smQg== 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=z0/Zo1rLDSxi7qxt1pPuM8s6wHm2XpbvzzFP5iHNqfs=; b=ePyAjn6IHkI9o3qLxBJSQKIJJF7RQ0XCCDNcCEzaK0xEAQ97bIdZ1b12lOSZAVdggl aPypwmZjIkVg1LVCDEdjFuWvzehrTEI11KlH9GqFwWB7Ku+fkbHDK39JRfy6+cso8A2T zbKoUOPog9jdMqHSVVSyOrt2CsEj3M2agPVYtSbJw823uKhiM5hbcdyRfdzIbyovpwbe uUhha/P6yoqRkyuDxVhsRtr9LHkbvAGN2pU4ys1AeTJxxMBb+CUZyqk+BJQiZbFqksjo 5Gznl1SwCP9/Yj2NQJBaMMA2MvQlAK9cNVg9ou/d1XijpBsvRzqzPhmxNHDUgBu7SWbc 6q2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b="U/6JC4Bn"; 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 v12-v6si111683plz.105.2018.07.25.19.34.30; Wed, 25 Jul 2018 19:34:45 -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="U/6JC4Bn"; 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 S1729109AbeGZDqc (ORCPT + 99 others); Wed, 25 Jul 2018 23:46:32 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:37667 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729068AbeGZDqb (ORCPT ); Wed, 25 Jul 2018 23:46:31 -0400 Received: by mail-ed1-f67.google.com with SMTP id b10-v6so337390eds.4 for ; Wed, 25 Jul 2018 19:31:57 -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=z0/Zo1rLDSxi7qxt1pPuM8s6wHm2XpbvzzFP5iHNqfs=; b=U/6JC4BnzxMboPkLVBVavLCIqOlvOVi2NLv6lzFswodbBBUZYel/XEfZqUJBhNyfWK 5CJSB75qCxbY3Tpn4PGgKpFzs1STR9wHNPGou+F+rcGztfTh6guwfsJnebPnXb4rkLh/ d3UdEWMl5uix0XCbpQ5mig3cLOXM75vctMYsudNH5KQMWzU34ijo58bj5VnqnkDYOmA2 WlVPQjOy+UyIRS0DNZFnoBTy67u9SnQ2gu/008KLpvlk+4fDT6gqj0emRa9zTS4kTXF2 zU1tLEaU3r7Ljn1frneRGc44aagVtu0pW4Yscw46Kk7Aq0kLVb4ciJk3lgeera6klzCA IWwQ== 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=z0/Zo1rLDSxi7qxt1pPuM8s6wHm2XpbvzzFP5iHNqfs=; b=TWNz+lAF4413mNeYZ+GxCN8O5DVXYZeDU78shvQsIzIEOAf/cgYBCIVd8K8CY/6Yy9 fG1A+AzCul1mMHAYz/AV2i0AM2j+VQMluBzJycx3pl1cvAvi208OKZbS/MZ0mnemyLOr IlYQ7sjGSEsgaUTbE/zOXjK30gpbYU1Ud4Ye1hee1wLnBMzV1tLMm8/deDtzCp9DnQqk 4zomY0ZoGb67mlt+VBlf7xaaQvN+nF1suLenW76XokNWczAHZiYnnnqlrQ2jzZga0oy7 0lRLh0U7ixUWyhTsgLE2+3gE/pfiRfK0tkOBWpcPjHTimNVOG3NvLN7KM/MQx9lx3SaM +zlg== X-Gm-Message-State: AOUpUlFcccvdKrx0vVarBbuaJYPUeJpMu2Xv7Ai2AtyA7N4p3EsoxUMM +ekW/U4vjCBz1eGWLpiMDHdgwHDhBjk= X-Received: by 2002:a50:c251:: with SMTP id t17-v6mr513489edf.108.1532572316829; Wed, 25 Jul 2018 19:31:56 -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.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Jul 2018 19:31:56 -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 09/18] xfrm: Dump usersa_info in compat/native formats Date: Thu, 26 Jul 2018 03:31:35 +0100 Message-Id: <20180726023144.31066-10-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 Create xfrm_usersa_info in netlink messages in 32/64-bit UABI according to type of syscall used to dump xfrm state. 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 | 55 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index b123e788488f..63622264a3a9 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -799,9 +799,9 @@ static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } -static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p) +static void __copy_to_user_state(struct xfrm_state *x, + struct xfrm_usersa_info_packed *p) { - memset(p, 0, sizeof(*p)); memcpy(&p->id, &x->id, sizeof(p->id)); memcpy(&p->sel, &x->sel, sizeof(p->sel)); memcpy(&p->lft, &x->lft, sizeof(p->lft)); @@ -818,11 +818,25 @@ static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p) p->seq = x->km.seq; } +static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p) +{ + memset(p, 0, sizeof(*p)); + __copy_to_user_state(x, (struct xfrm_usersa_info_packed *)p); +} + +static void copy_to_user_state_compat(struct xfrm_state *x, + struct xfrm_usersa_info_packed *p) +{ + memset(p, 0, sizeof(*p)); + __copy_to_user_state(x, p); +} + struct xfrm_dump_info { struct sk_buff *in_skb; struct sk_buff *out_skb; u32 nlmsg_seq; u16 nlmsg_flags; + bool compat_dump; }; static int copy_sec_ctx(struct xfrm_sec_ctx *s, struct sk_buff *skb) @@ -882,14 +896,10 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb) } /* Don't change this without updating xfrm_sa_len! */ -static int copy_to_user_state_extra(struct xfrm_state *x, - struct xfrm_usersa_info *p, - struct sk_buff *skb) +static int __copy_to_user_state_extra(struct xfrm_state *x, struct sk_buff *skb) { int ret = 0; - copy_to_user_state(x, p); - if (x->props.extra_flags) { ret = nla_put_u32(skb, XFRMA_SA_EXTRA_FLAGS, x->props.extra_flags); @@ -968,23 +978,42 @@ static int copy_to_user_state_extra(struct xfrm_state *x, return ret; } +static int copy_to_user_state_extra(struct xfrm_state *x, + struct xfrm_usersa_info *p, struct sk_buff *skb) +{ + copy_to_user_state(x, p); + return __copy_to_user_state_extra(x, skb); +} + +static int copy_to_user_state_extra_compat(struct xfrm_state *x, + struct xfrm_usersa_info_packed *p, struct sk_buff *skb) +{ + copy_to_user_state_compat(x, p); + return __copy_to_user_state_extra(x, skb); +} + static int dump_one_state(struct xfrm_state *x, int count, void *ptr) { struct xfrm_dump_info *sp = ptr; struct sk_buff *in_skb = sp->in_skb; struct sk_buff *skb = sp->out_skb; - struct xfrm_usersa_info *p; struct nlmsghdr *nlh; + size_t msg_len; int err; + if (sp->compat_dump) + msg_len = sizeof(struct xfrm_usersa_info_packed); + else + msg_len = sizeof(struct xfrm_usersa_info); nlh = nlmsg_put(skb, NETLINK_CB(in_skb).portid, sp->nlmsg_seq, - XFRM_MSG_NEWSA, sizeof(*p), sp->nlmsg_flags); + XFRM_MSG_NEWSA, msg_len, sp->nlmsg_flags); if (nlh == NULL) return -EMSGSIZE; - p = nlmsg_data(nlh); - - err = copy_to_user_state_extra(x, p, skb); + if (sp->compat_dump) + err = copy_to_user_state_extra_compat(x, nlmsg_data(nlh), skb); + else + err = copy_to_user_state_extra(x, nlmsg_data(nlh), skb); if (err) { nlmsg_cancel(skb, nlh); return err; @@ -1018,6 +1047,7 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb) info.out_skb = skb; info.nlmsg_seq = cb->nlh->nlmsg_seq; info.nlmsg_flags = NLM_F_MULTI; + info.compat_dump = in_compat_syscall(); if (!cb->args[0]) { struct nlattr *attrs[XFRMA_MAX+1]; @@ -1064,6 +1094,7 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb, info.out_skb = skb; info.nlmsg_seq = seq; info.nlmsg_flags = 0; + info.compat_dump = in_compat_syscall(); err = dump_one_state(x, 0, &info); if (err) { -- 2.13.6