@@ -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 )
@@ -741,13 +751,18 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
741
751
{
742
752
char * name ;
743
753
struct nlattr * link ;
754
+ int len ;
744
755
745
756
name = (char * )TLV_DATA (msg -> req );
746
757
747
758
link = nla_nest_start (skb , TIPC_NLA_LINK );
748
759
if (!link )
749
760
return - EMSGSIZE ;
750
761
762
+ len = min_t (int , TLV_GET_DATA_LEN (msg -> req ), TIPC_MAX_LINK_NAME );
763
+ if (!string_is_valid (name , len ))
764
+ return - EINVAL ;
765
+
751
766
if (nla_put_string (skb , TIPC_NLA_LINK_NAME , name ))
752
767
return - EMSGSIZE ;
753
768
0 commit comments