From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH] netlink: add policy attribute range validation
Date: Wed, 26 Sep 2018 22:35:27 +0200 [thread overview]
Message-ID: <1537994127.28767.39.camel@sipsolutions.net> (raw)
In-Reply-To: <1537993066.28767.29.camel@sipsolutions.net> (sfid-20180926_221836_321005_FEBFE2B4)
On Wed, 2018-09-26 at 22:17 +0200, Johannes Berg wrote:
> On Wed, 2018-09-26 at 22:06 +0200, Johannes Berg wrote:
> > From: Johannes Berg <johannes.berg@intel.com>
> >
> > Without further bloating the policy structs, we can overload
> > the `validation_data' pointer with a struct of s16 min, max
> > and use those to validate ranges in NLA_{U,S}{8,16,32,64}
> > attributes.
> >
> > It may sound strange to validate NLA_U32 with a s16 max, but
> > in many cases NLA_U32 is used for enums etc. since there's no
> > size benefit in using a smaller attribute width anyway, due
> > to netlink attribute alignment; in cases like that it's still
> > useful, particularly when the attribute really transports an
> > enum value.
>
> That said, I did find a few places where we could benefit from a larger
> type here - e.g. having a NLA_U16 that must be non-zero cannot be
> represented in the policy as is, since you can't set max to 65535.
We could also fix that, btw, by taking two bits out of the "type" field,
and letting those indicate "check_min" and "check_max". That would also
fix the other thing I noted regarding the union, I suppose.
I didn't really like that too much because it makes the whole thing far
more complex, but perhaps if we hide it behind macros like
#define NLA_POLICY_RANGE(tp, _min, _max) {
.type = tp,
.min = _min, .check_min = 1,
.max = _max, .check_max = 1,
}
#define NLA_POLICY_MIN(tp, _min) {
.type = tp,
.min = _min, .check_min = 1,
}
#define NLA_POLICY_MAX(tp, _max) {
.type = tp,
.max = _max, .check_max = 1,
}
it becomes more palatable?
johannes
next prev parent reply other threads:[~2018-09-26 20:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-26 20:06 [PATCH] netlink: add policy attribute range validation Johannes Berg
2018-09-26 20:07 ` [RFC] nl80211: use policy range validation where applicable Johannes Berg
2018-09-26 20:09 ` Johannes Berg
2018-09-26 20:17 ` [PATCH] netlink: add policy attribute range validation Johannes Berg
2018-09-26 20:35 ` Johannes Berg [this message]
2018-09-27 7:16 ` Michal Kubecek
2018-09-27 8:12 ` Johannes Berg
2018-09-27 8:48 ` Michal Kubecek
2018-09-27 8:51 ` Johannes Berg
2018-09-26 20:24 ` Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1537994127.28767.39.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).