@@ -87,6 +87,11 @@ static int tipc_skb_tailroom(struct sk_buff *skb)
87
87
return limit ;
88
88
}
89
89
90
+ static inline int TLV_GET_DATA_LEN (struct tlv_desc * tlv )
91
+ {
92
+ return TLV_GET_LEN (tlv ) - TLV_SPACE (0 );
93
+ }
94
+
90
95
static int tipc_add_tlv (struct sk_buff * skb , u16 type , void * data , u16 len )
91
96
{
92
97
struct tlv_desc * tlv = (struct tlv_desc * )skb_tail_pointer (skb );
@@ -166,6 +171,11 @@ static struct sk_buff *tipc_get_err_tlv(char *str)
166
171
return buf ;
167
172
}
168
173
174
+ static inline bool string_is_valid (char * s , int len )
175
+ {
176
+ return memchr (s , '\0' , len ) ? true : false;
177
+ }
178
+
169
179
static int __tipc_nl_compat_dumpit (struct tipc_nl_compat_cmd_dump * cmd ,
170
180
struct tipc_nl_compat_msg * msg ,
171
181
struct sk_buff * arg )
@@ -750,13 +760,18 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
750
760
{
751
761
char * name ;
752
762
struct nlattr * link ;
763
+ int len ;
753
764
754
765
name = (char * )TLV_DATA (msg -> req );
755
766
756
767
link = nla_nest_start (skb , TIPC_NLA_LINK );
757
768
if (!link )
758
769
return - EMSGSIZE ;
759
770
771
+ len = min_t (int , TLV_GET_DATA_LEN (msg -> req ), TIPC_MAX_LINK_NAME );
772
+ if (!string_is_valid (name , len ))
773
+ return - EINVAL ;
774
+
760
775
if (nla_put_string (skb , TIPC_NLA_LINK_NAME , name ))
761
776
return - EMSGSIZE ;
762
777
0 commit comments