netlink: allow NLA_MSECS to have range validation
authorJohannes Berg <johannes.berg@intel.com>
Thu, 30 Apr 2020 20:13:09 +0000 (22:13 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 May 2020 00:51:42 +0000 (17:51 -0700)
Since NLA_MSECS is really equivalent to NLA_U64, allow
it to have range validation as well.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netlink.h
lib/nlattr.c

index 94a7df4ab1226cca736b861ea1579360ee049683..4acd7165e900c103a401566394aca9dafd1fd57b 100644 (file)
@@ -371,7 +371,8 @@ struct nla_policy {
 #define __NLA_ENSURE(condition) BUILD_BUG_ON_ZERO(!(condition))
 #define NLA_ENSURE_UINT_TYPE(tp)                       \
        (__NLA_ENSURE(tp == NLA_U8 || tp == NLA_U16 ||  \
-                     tp == NLA_U32 || tp == NLA_U64) + tp)
+                     tp == NLA_U32 || tp == NLA_U64 || \
+                     tp == NLA_MSECS) + tp)
 #define NLA_ENSURE_SINT_TYPE(tp)                       \
        (__NLA_ENSURE(tp == NLA_S8 || tp == NLA_S16  || \
                      tp == NLA_S32 || tp == NLA_S64) + tp)
@@ -379,7 +380,8 @@ struct nla_policy {
        (__NLA_ENSURE(tp == NLA_S8 || tp == NLA_U8 ||   \
                      tp == NLA_S16 || tp == NLA_U16 || \
                      tp == NLA_S32 || tp == NLA_U32 || \
-                     tp == NLA_S64 || tp == NLA_U64) + tp)
+                     tp == NLA_S64 || tp == NLA_U64 || \
+                     tp == NLA_MSECS) + tp)
 #define NLA_ENSURE_NO_VALIDATION_PTR(tp)               \
        (__NLA_ENSURE(tp != NLA_BITFIELD32 &&           \
                      tp != NLA_REJECT &&               \
index a8beb173f558aff41f83a8cd8c15ee5f4204fa8e..21ef3998b9d9916a98959c791e9cd955ac960710 100644 (file)
@@ -151,6 +151,7 @@ static int nla_validate_int_range_unsigned(const struct nla_policy *pt,
                value = nla_get_u32(nla);
                break;
        case NLA_U64:
+       case NLA_MSECS:
                value = nla_get_u64(nla);
                break;
        default:
@@ -227,6 +228,7 @@ static int nla_validate_int_range(const struct nla_policy *pt,
        case NLA_U16:
        case NLA_U32:
        case NLA_U64:
+       case NLA_MSECS:
                return nla_validate_int_range_unsigned(pt, nla, extack);
        case NLA_S8:
        case NLA_S16: