Skip to contentSkip to conversation

BROKEN Re: [PATCH] netlink: 2-clause nla_ok()

PATCH Applied Alexey Dobriyan 3 participants 4 messages Dec 5, 2016 – Dec 13, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

David, please do

    git revert 4f7df337fe79bba1e4c2d525525d63b5ba186bbd

I'm an idiot.

All rationale in the commit would be correct if reading "nla_len" didn't require memory access. But it does.

    return rem >= (int)sizeof(*nla) &&
               nla->nla_len >= sizeof(*nla) &&
               nla->nla_len <= remaining;

Those logical ands ensure that memory access is not done if "rem" is small enough to even fetch ->nla_len.

Maybe someone could vouch that other checks prevent this kind of situation from happening but not me. How very embarrassing.

#1 lore raw
Quoted 3 lines

Maybe someone could vouch that other checks prevent this kind of situation from happening but not me.

No, now that you spell it out (and I see the patch) - this is absolutely needed because nla_for_each_attr() [1] can be called on arbitrary data coming from userspace in a message, e.g. by way of nla_for_each_nested(). Even if it's not malformed, nla_ok() is the only abort condition for that loop, so it would read at least one nla_len after the real buffer without that condition.

johannes

[1] which seems to be the only significant user thereof

#2 lore raw

PATCH 1/1 netlink: revert broken, broken "2-clause nla_ok()"

Commit 4f7df337fe79bba1e4c2d525525d63b5ba186bbd
"netlink: 2-clause nla_ok()" is BROKEN.

First clause tests if "->nla_len" could even be accessed at all, it can not possibly be omitted.

---

 include/net/netlink.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/net/netlink.h +2 -1
@@ -698,7 +698,8 @@ static inline int nla_len(const struct nlattr *nla)
  */
 static inline int nla_ok(const struct nlattr *nla, int remaining)
 {
-	return nla->nla_len >= sizeof(*nla) &&
+	return remaining >= (int) sizeof(*nla) &&
+	       nla->nla_len >= sizeof(*nla) &&
 	       nla->nla_len <= remaining;
 }
 
maintainer Applied
#3 lore raw

Re: [PATCH net-next] netlink: revert broken, broken "2-clause nla_ok()"

From: Alexey Dobriyan <[email protected]>
Date: Tue, 13 Dec 2016 22:30:15 +0300

Quoted 7 lines

Commit 4f7df337fe79bba1e4c2d525525d63b5ba186bbd
"netlink: 2-clause nla_ok()" is BROKEN.

First clause tests if "->nla_len" could even be accessed at all, it can not possibly be omitted.

Applied, thanks.