mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
genetlink: optionally validate strictly/dumps
Add options to strictly validate messages and dump messages,
sometimes perhaps validating dump messages non-strictly may
be required, so add an option for that as well.
Since none of this can really be applied to existing commands,
set the options everwhere using the following spatch:
@@
identifier ops;
expression X;
@@
struct genl_ops ops[] = {
...,
{
.cmd = X,
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
...
},
...
};
For new commands one should just not copy the .validate 'opt-out'
flags and thus get strict validation.
Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
parent
56738f4608
commit
ef6243acb4
37 changed files with 405 additions and 3 deletions
|
|
@ -536,6 +536,24 @@ static int genl_family_rcv_msg(const struct genl_family *family,
|
|||
if (ops->dumpit == NULL)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (!(ops->validate & GENL_DONT_VALIDATE_DUMP)) {
|
||||
unsigned int validate = NL_VALIDATE_STRICT;
|
||||
int hdrlen = GENL_HDRLEN + family->hdrsize;
|
||||
|
||||
if (ops->validate & GENL_DONT_VALIDATE_DUMP_STRICT)
|
||||
validate = NL_VALIDATE_LIBERAL;
|
||||
|
||||
if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
|
||||
return -EINVAL;
|
||||
|
||||
rc = __nla_validate(nlmsg_attrdata(nlh, hdrlen),
|
||||
nlmsg_attrlen(nlh, hdrlen),
|
||||
family->maxattr, family->policy,
|
||||
validate, extack);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!family->parallel_ops) {
|
||||
struct netlink_dump_control c = {
|
||||
.module = family->module,
|
||||
|
|
@ -577,9 +595,13 @@ static int genl_family_rcv_msg(const struct genl_family *family,
|
|||
attrbuf = family->attrbuf;
|
||||
|
||||
if (attrbuf) {
|
||||
err = nlmsg_parse_deprecated(nlh, hdrlen, attrbuf,
|
||||
family->maxattr, family->policy,
|
||||
extack);
|
||||
enum netlink_validation validate = NL_VALIDATE_STRICT;
|
||||
|
||||
if (ops->validate & GENL_DONT_VALIDATE_STRICT)
|
||||
validate = NL_VALIDATE_LIBERAL;
|
||||
|
||||
err = __nlmsg_parse(nlh, hdrlen, attrbuf, family->maxattr,
|
||||
family->policy, validate, extack);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -939,6 +961,7 @@ static int genl_ctrl_event(int event, const struct genl_family *family,
|
|||
static const struct genl_ops genl_ctrl_ops[] = {
|
||||
{
|
||||
.cmd = CTRL_CMD_GETFAMILY,
|
||||
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
||||
.doit = ctrl_getfamily,
|
||||
.dumpit = ctrl_dumpfamily,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue