Skip to content

Commit a02d83f

Browse files
mihalicyndavem330
authored andcommitted
scm: fix MSG_CTRUNC setting condition for SO_PASSSEC
Currently, kernel would set MSG_CTRUNC flag if msg_control buffer wasn't provided and SO_PASSCRED was set or if there was pending SCM_RIGHTS. For some reason we have no corresponding check for SO_PASSSEC. In the recvmsg(2) doc we have: MSG_CTRUNC indicates that some control data was discarded due to lack of space in the buffer for ancillary data. So, we need to set MSG_CTRUNC flag for all types of SCM. This change can break applications those don't check MSG_CTRUNC flag. Cc: "David S. Miller" <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: Leon Romanovsky <[email protected]> Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Alexander Mikhalitsyn <[email protected]> v2: - commit message was rewritten according to Eric's suggestion Acked-by: Paul Moore <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c4216a8 commit a02d83f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

include/net/scm.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,27 @@ static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct sc
105105
}
106106
}
107107
}
108+
109+
static inline bool scm_has_secdata(struct socket *sock)
110+
{
111+
return test_bit(SOCK_PASSSEC, &sock->flags);
112+
}
108113
#else
109114
static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm)
110115
{ }
116+
117+
static inline bool scm_has_secdata(struct socket *sock)
118+
{
119+
return false;
120+
}
111121
#endif /* CONFIG_SECURITY_NETWORK */
112122

113123
static __inline__ void scm_recv(struct socket *sock, struct msghdr *msg,
114124
struct scm_cookie *scm, int flags)
115125
{
116126
if (!msg->msg_control) {
117-
if (test_bit(SOCK_PASSCRED, &sock->flags) || scm->fp)
127+
if (test_bit(SOCK_PASSCRED, &sock->flags) || scm->fp ||
128+
scm_has_secdata(sock))
118129
msg->msg_flags |= MSG_CTRUNC;
119130
scm_destroy(scm);
120131
return;

0 commit comments

Comments
 (0)