Skip to content

Commit 157ffff

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nfnetlink_cthelper: reject too large userspace allocation requests
Userspace should not abuse the kernel to store large amounts of data, reject requests larger than the private area can accommodate. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent dcf6774 commit 157ffff

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

net/netfilter/nfnetlink_cthelper.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ nfnl_cthelper_from_nlattr(struct nlattr *attr, struct nf_conn *ct)
104104
if (help->helper->data_len == 0)
105105
return -EINVAL;
106106

107-
memcpy(help->data, nla_data(attr), help->helper->data_len);
107+
nla_memcpy(help->data, nla_data(attr), sizeof(help->data));
108108
return 0;
109109
}
110110

@@ -216,6 +216,7 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
216216
{
217217
struct nf_conntrack_helper *helper;
218218
struct nfnl_cthelper *nfcth;
219+
unsigned int size;
219220
int ret;
220221

221222
if (!tb[NFCTH_TUPLE] || !tb[NFCTH_POLICY] || !tb[NFCTH_PRIV_DATA_LEN])
@@ -231,7 +232,12 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
231232
goto err1;
232233

233234
strncpy(helper->name, nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN);
234-
helper->data_len = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN]));
235+
size = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN]));
236+
if (size > FIELD_SIZEOF(struct nf_conn_help, data)) {
237+
ret = -ENOMEM;
238+
goto err2;
239+
}
240+
235241
helper->flags |= NF_CT_HELPER_F_USERSPACE;
236242
memcpy(&helper->tuple, tuple, sizeof(struct nf_conntrack_tuple));
237243

0 commit comments

Comments
 (0)