selinux/nlmsg: add a build time check for rtnl/xfrm cmds
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Mon, 13 Apr 2015 13:20:37 +0000 (15:20 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 13 Apr 2015 17:09:44 +0000 (13:09 -0400)
When a new rtnl or xfrm command is added, this part of the code is frequently
missing. Let's help the developer with a build time test.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
security/selinux/nlmsgtab.c

index 30594bfa5fb1c00fffed6e353b21acd4afbf3c28..2bbb41822d8ec8882f8dacbbb4c5f8a1feac59ca 100644 (file)
@@ -153,6 +153,8 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)
 
        switch (sclass) {
        case SECCLASS_NETLINK_ROUTE_SOCKET:
+               /* RTM_MAX always point to RTM_SETxxxx, ie RTM_NEWxxx + 3 */
+               BUILD_BUG_ON(RTM_MAX != (RTM_NEWNSID + 3));
                err = nlmsg_perm(nlmsg_type, perm, nlmsg_route_perms,
                                 sizeof(nlmsg_route_perms));
                break;
@@ -163,6 +165,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)
                break;
 
        case SECCLASS_NETLINK_XFRM_SOCKET:
+               BUILD_BUG_ON(XFRM_MSG_MAX != XFRM_MSG_MAPPING);
                err = nlmsg_perm(nlmsg_type, perm, nlmsg_xfrm_perms,
                                 sizeof(nlmsg_xfrm_perms));
                break;