Re: [PATCH 4/4] xfrm_user: Add new 32/64-agnostic netlink messages

2017-01-21 Thread kbuild test robot
Hi Kevin,

[auto build test ERROR on ipsec-next/master]
[also build test ERROR on v4.10-rc4 next-20170120]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Kevin-Cernekee/Make-xfrm-usable-by-32-bit-programs/20170121-150712
base:   https://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git 
master
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 6.2.0
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64 

All errors (new ones prefixed by >>):

>> net/xfrm/xfrm_user_legacy.c:845:5: error: redefinition of 
>> 'xfrm_exp_state_notify_legacy'
int xfrm_exp_state_notify_legacy(const struct xfrm_state *x,
^~~~
   In file included from net/xfrm/xfrm_user_legacy.c:30:0:
   net/xfrm/xfrm_user.h:131:19: note: previous definition of 
'xfrm_exp_state_notify_legacy' was here
static inline int xfrm_exp_state_notify_legacy(const struct xfrm_state *x,
  ^~~~
>> net/xfrm/xfrm_user_legacy.c:863:5: error: redefinition of 
>> 'xfrm_notify_sa_legacy'
int xfrm_notify_sa_legacy(const struct xfrm_state *x, const struct km_event 
*c)
^
   In file included from net/xfrm/xfrm_user_legacy.c:30:0:
   net/xfrm/xfrm_user.h:137:19: note: previous definition of 
'xfrm_notify_sa_legacy' was here
static inline int xfrm_notify_sa_legacy(const struct xfrm_state *x,
  ^
>> net/xfrm/xfrm_user_legacy.c:983:5: error: redefinition of 
>> 'xfrm_send_acquire_legacy'
int xfrm_send_acquire_legacy(struct xfrm_state *x,
^~~~
   In file included from net/xfrm/xfrm_user_legacy.c:30:0:
   net/xfrm/xfrm_user.h:143:19: note: previous definition of 
'xfrm_send_acquire_legacy' was here
static inline int xfrm_send_acquire_legacy(struct xfrm_state *x,
  ^~~~
>> net/xfrm/xfrm_user_legacy.c:1043:5: error: redefinition of 
>> 'xfrm_exp_policy_notify_legacy'
int xfrm_exp_policy_notify_legacy(const struct xfrm_policy *xp,
^
   In file included from net/xfrm/xfrm_user_legacy.c:30:0:
   net/xfrm/xfrm_user.h:150:19: note: previous definition of 
'xfrm_exp_policy_notify_legacy' was here
static inline int xfrm_exp_policy_notify_legacy(const struct xfrm_policy 
*xp,
  ^
>> net/xfrm/xfrm_user_legacy.c:1060:5: error: redefinition of 
>> 'xfrm_notify_policy_legacy'
int xfrm_notify_policy_legacy(const struct xfrm_policy *xp,
^
   In file included from net/xfrm/xfrm_user_legacy.c:30:0:
   net/xfrm/xfrm_user.h:157:19: note: previous definition of 
'xfrm_notify_policy_legacy' was here
static inline int xfrm_notify_policy_legacy(const struct xfrm_policy *xp,
  ^

vim +/xfrm_exp_state_notify_legacy +845 net/xfrm/xfrm_user_legacy.c

   839  return err;
   840  
   841  nlmsg_end(skb, nlh);
   842  return 0;
   843  }
   844  
 > 845  int xfrm_exp_state_notify_legacy(const struct xfrm_state *x,
   846   const struct km_event *c)
   847  {
   848  struct net *net = xs_net(x);
   849  struct sk_buff *skb;
   850  
   851  skb = nlmsg_new(xfrm_expire_msgsize(), GFP_ATOMIC);
   852  if (skb == NULL)
   853  return -ENOMEM;
   854  
   855  if (build_expire(skb, x, c) < 0) {
   856  kfree_skb(skb);
   857  return -EMSGSIZE;
   858  }
   859  
   860  return xfrm_nlmsg_multicast(net, skb, 0, XFRMNLGRP_EXPIRE);
   861  }
   862  
 > 863  int xfrm_notify_sa_legacy(const struct xfrm_state *x, const struct 
 > km_event *c)
   864  {
   865  struct net *net = xs_net(x);
   866  struct xfrm_usersa_info_legacy *p;
   867  struct xfrm_usersa_id *id;
   868  struct nlmsghdr *nlh;
   869  struct sk_buff *skb;
   870  int len = xfrm_sa_len(x);
   871  int headlen, err;
   872  u32 event = 0;
   873  
   874  headlen = sizeof(*p);
   875  if (c->event == XFRM_MSG_DELSA) {
   876  len += nla_total_size(headlen);
   877  headlen = sizeof(*id);
   878  len += nla_total_size(sizeof(struct xfrm_mark));
   879  }
   880  len += NLMSG_ALIGN(headlen);
   881  
   882  skb = nlmsg_new(len, GFP_ATOMIC);
   883  if (skb == NULL)
   884  return -ENOMEM;
   885  
   886  switch (c->event) {
   887  case XFRM_MSG_NEWSA:
   

[PATCH 4/4] xfrm_user: Add new 32/64-agnostic netlink messages

2017-01-20 Thread Kevin Cernekee
Add several new message types to address longstanding 32-bit/64-bit
compatibility issues.  Use xfrm_user_legacy to handle the existing
message types, which will retain the old IDs for compatibility with
existing binaries.

For user->kernel messages, the nlmsg_type will determine whether to use
the old format or the new format (for both requests and replies).  For
kernel->user multicasts, both types will be sent.

setsockopt() will deduce the format from the length.

Signed-off-by: Kevin Cernekee 
---
 include/uapi/linux/xfrm.h   | 152 ++-
 net/xfrm/xfrm_user.c| 136 ---
 net/xfrm/xfrm_user.h|  75 
 net/xfrm/xfrm_user_legacy.c | 169 
 security/selinux/nlmsgtab.c |  61 +---
 5 files changed, 466 insertions(+), 127 deletions(-)

diff --git a/include/uapi/linux/xfrm.h b/include/uapi/linux/xfrm.h
index 1fc62b239f1b..ae5f97681989 100644
--- a/include/uapi/linux/xfrm.h
+++ b/include/uapi/linux/xfrm.h
@@ -1,6 +1,7 @@
 #ifndef _LINUX_XFRM_H
 #define _LINUX_XFRM_H
 
+#include 
 #include 
 #include 
 
@@ -157,34 +158,34 @@ enum {
 enum {
XFRM_MSG_BASE = 0x10,
 
-   XFRM_MSG_NEWSA = 0x10,
-#define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
-   XFRM_MSG_DELSA,
-#define XFRM_MSG_DELSA XFRM_MSG_DELSA
-   XFRM_MSG_GETSA,
-#define XFRM_MSG_GETSA XFRM_MSG_GETSA
-
-   XFRM_MSG_NEWPOLICY,
-#define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
-   XFRM_MSG_DELPOLICY,
-#define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
-   XFRM_MSG_GETPOLICY,
-#define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
-
-   XFRM_MSG_ALLOCSPI,
-#define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
-   XFRM_MSG_ACQUIRE,
-#define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
-   XFRM_MSG_EXPIRE,
-#define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
-
-   XFRM_MSG_UPDPOLICY,
-#define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
-   XFRM_MSG_UPDSA,
-#define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
-
-   XFRM_MSG_POLEXPIRE,
-#define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
+   XFRM_MSG_NEWSA_LEGACY = 0x10,
+#define XFRM_MSG_NEWSA_LEGACY XFRM_MSG_NEWSA_LEGACY
+   XFRM_MSG_DELSA_LEGACY,
+#define XFRM_MSG_DELSA_LEGACY XFRM_MSG_DELSA_LEGACY
+   XFRM_MSG_GETSA_LEGACY,
+#define XFRM_MSG_GETSA_LEGACY XFRM_MSG_GETSA_LEGACY
+
+   XFRM_MSG_NEWPOLICY_LEGACY,
+#define XFRM_MSG_NEWPOLICY_LEGACY XFRM_MSG_NEWPOLICY_LEGACY
+   XFRM_MSG_DELPOLICY_LEGACY,
+#define XFRM_MSG_DELPOLICY_LEGACY XFRM_MSG_DELPOLICY_LEGACY
+   XFRM_MSG_GETPOLICY_LEGACY,
+#define XFRM_MSG_GETPOLICY_LEGACY XFRM_MSG_GETPOLICY_LEGACY
+
+   XFRM_MSG_ALLOCSPI_LEGACY,
+#define XFRM_MSG_ALLOCSPI_LEGACY XFRM_MSG_ALLOCSPI_LEGACY
+   XFRM_MSG_ACQUIRE_LEGACY,
+#define XFRM_MSG_ACQUIRE_LEGACY XFRM_MSG_ACQUIRE_LEGACY
+   XFRM_MSG_EXPIRE_LEGACY,
+#define XFRM_MSG_EXPIRE_LEGACY XFRM_MSG_EXPIRE_LEGACY
+
+   XFRM_MSG_UPDPOLICY_LEGACY,
+#define XFRM_MSG_UPDPOLICY_LEGACY XFRM_MSG_UPDPOLICY_LEGACY
+   XFRM_MSG_UPDSA_LEGACY,
+#define XFRM_MSG_UPDSA_LEGACY XFRM_MSG_UPDSA_LEGACY
+
+   XFRM_MSG_POLEXPIRE_LEGACY,
+#define XFRM_MSG_POLEXPIRE_LEGACY XFRM_MSG_POLEXPIRE_LEGACY
 
XFRM_MSG_FLUSHSA,
 #define XFRM_MSG_FLUSHSA XFRM_MSG_FLUSHSA
@@ -214,6 +215,34 @@ enum {
 
XFRM_MSG_MAPPING,
 #define XFRM_MSG_MAPPING XFRM_MSG_MAPPING
+
+   XFRM_MSG_ALLOCSPI,
+#define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
+   XFRM_MSG_ACQUIRE,
+#define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
+   XFRM_MSG_EXPIRE,
+#define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
+   XFRM_MSG_POLEXPIRE,
+#define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
+
+   XFRM_MSG_NEWSA,
+#define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
+   XFRM_MSG_UPDSA,
+#define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
+   XFRM_MSG_DELSA,
+#define XFRM_MSG_DELSA XFRM_MSG_DELSA
+   XFRM_MSG_GETSA,
+#define XFRM_MSG_GETSA XFRM_MSG_GETSA
+
+   XFRM_MSG_NEWPOLICY,
+#define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
+   XFRM_MSG_UPDPOLICY,
+#define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
+   XFRM_MSG_DELPOLICY,
+#define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
+   XFRM_MSG_GETPOLICY,
+#define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
+
__XFRM_MSG_MAX
 };
 #define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
@@ -221,7 +250,7 @@ enum {
 #define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
 
 /*
- * Generic LSM security context for comunicating to user space
+ * Generic LSM security context for communicating to user space
  * NOTE: Same format as sadb_x_sec_ctx
  */
 struct xfrm_user_sec_ctx {
@@ -357,6 +386,22 @@ struct xfrmu_spdhthresh {
__u8 rbits;
 };
 
+/* Legacy structs are incompatible between 32-bit and 64-bit. */
+struct xfrm_usersa_info_legacy {
+   struct xfrm_selectorsel;
+   struct xfrm_id  id;
+   xfrm_address_t  saddr;
+   struct xfrm_lifetime_cfglft;
+   struct xfrm_lifetime_curcurlft;
+