Patchwork net: fix incorrect credentials passing

login
register
mail settings
Submitter Linus Torvalds
Date April 20, 2013, 1:32 a.m.
Message ID <alpine.LFD.2.03.1304191826080.2455@gmail.com>
Download mbox | patch
Permalink /patch/238135/
State Accepted
Delegated to: David Miller
Headers show

Comments

Linus Torvalds - April 20, 2013, 1:32 a.m.
Commit 257b5358b32f ("scm: Capture the full credentials of the scm 
sender") changed the credentials passing code to pass in the effective 
uid/gid instead of the real uid/gid.

Obviously this doesn't matter most of the time (since normally they are 
the same), but it results in differences for suid binaries when the wrong 
uid/gid ends up being used.

This just undoes that (presumably unintentional) part of the commit.

Reported-by: Andy Lutomirski <luto@amacapital.net>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Serge E. Hallyn <serge@hallyn.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

 include/net/scm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - April 20, 2013, 1:58 a.m.
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Fri, 19 Apr 2013 18:32:32 -0700 (PDT)

> Commit 257b5358b32f ("scm: Capture the full credentials of the scm 
> sender") changed the credentials passing code to pass in the effective 
> uid/gid instead of the real uid/gid.

Yep, that's exactly what happened, via a very twisty and winding road.

The helper cred_to_ucred(), which was created by commit
3f551f9436c05a3b5eccdd6e94733df5bb98d2a5 ("sock: Introduce
cred_to_ucred") seemed to be aimed at providing the semantics expected
by SO_PEERCRED, which does in fact want to use the effective UIDs and
GIDs.

The SO_PEERCRED side of this can be seen more clearly in commit
109f6e39fa07c48f580125f531f46cb7c245b528 ("af_unix: Allow SO_PEERCRED
to work across namespaces.")

The error begins when we try to use that helper in the SCM credentials
code.

Initially, cred_to_ucred() is what was used by scm_set_cred().  Then
it got changed in dbe9a4173ea53b72b2c35d19f676a85b69f1c9fe ("scm:
Don't use struct ucred in NETLINK_CB and struct scm_cookie.") which
continues the error by propagating the effective UID/GID usage from
cred_to_ucred() into explicit accesses inside of scm_set_cred().

So, as stated, the error originates from trying to use this common
helper for both SO_PEERCERD and the SCM stuff, the latter of which
does not want to use effective UIDs and GIDs.

> This just undoes that (presumably unintentional) part of the commit.

Indeed, I'd say this was an oversight in semantic differences when
creating the cred_to_ucred() helper.

Eric B. please review and ACK this.

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric W. Biederman - April 20, 2013, 10:53 a.m.
David Miller <davem@davemloft.net> writes:

> From: Linus Torvalds <torvalds@linux-foundation.org>
> Date: Fri, 19 Apr 2013 18:32:32 -0700 (PDT)
>
>> Commit 257b5358b32f ("scm: Capture the full credentials of the scm 
>> sender") changed the credentials passing code to pass in the effective 
>> uid/gid instead of the real uid/gid.
>
> Yep, that's exactly what happened, via a very twisty and winding road.
>
> The helper cred_to_ucred(), which was created by commit
> 3f551f9436c05a3b5eccdd6e94733df5bb98d2a5 ("sock: Introduce
> cred_to_ucred") seemed to be aimed at providing the semantics expected
> by SO_PEERCRED, which does in fact want to use the effective UIDs and
> GIDs.
>
> The SO_PEERCRED side of this can be seen more clearly in commit
> 109f6e39fa07c48f580125f531f46cb7c245b528 ("af_unix: Allow SO_PEERCRED
> to work across namespaces.")
>
> The error begins when we try to use that helper in the SCM credentials
> code.
>
> Initially, cred_to_ucred() is what was used by scm_set_cred().  Then
> it got changed in dbe9a4173ea53b72b2c35d19f676a85b69f1c9fe ("scm:
> Don't use struct ucred in NETLINK_CB and struct scm_cookie.") which
> continues the error by propagating the effective UID/GID usage from
> cred_to_ucred() into explicit accesses inside of scm_set_cred().
>
> So, as stated, the error originates from trying to use this common
> helper for both SO_PEERCERD and the SCM stuff, the latter of which
> does not want to use effective UIDs and GIDs.
>
>> This just undoes that (presumably unintentional) part of the commit.
>
> Indeed, I'd say this was an oversight in semantic differences when
> creating the cred_to_ucred() helper.
>
> Eric B. please review and ACK this.

I have followed this only briefly and looked at this only quickly but I
David I read the git history the same way you do.  I introduced a
behavior change when the cred_to_ucred helper was introduced into
scm_set_cred().  Linus's patch restores the original behavior.

So.

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>

Hopefully that is sufficient.  I am in the midst of taking care of some
non-software things this week and I really don't have the time to look
more closely.

Eric

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - April 20, 2013, 8:58 p.m.
From: ebiederm@xmission.com (Eric W. Biederman)
Date: Sat, 20 Apr 2013 03:53:50 -0700

> I have followed this only briefly and looked at this only quickly but I
> David I read the git history the same way you do.  I introduced a
> behavior change when the cred_to_ucred helper was introduced into
> scm_set_cred().  Linus's patch restores the original behavior.
> 
> So.
> 
> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>

Thanks for reviewing Eric.

Applied and queued up for -stable, thanks everyone.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/include/net/scm.h b/include/net/scm.h
index 975cca01048b..b11708105681 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -56,8 +56,8 @@  static __inline__ void scm_set_cred(struct scm_cookie *scm,
 	scm->pid  = get_pid(pid);
 	scm->cred = cred ? get_cred(cred) : NULL;
 	scm->creds.pid = pid_vnr(pid);
-	scm->creds.uid = cred ? cred->euid : INVALID_UID;
-	scm->creds.gid = cred ? cred->egid : INVALID_GID;
+	scm->creds.uid = cred ? cred->uid : INVALID_UID;
+	scm->creds.gid = cred ? cred->gid : INVALID_GID;
 }
 
 static __inline__ void scm_destroy_cred(struct scm_cookie *scm)