Bug Report: bug if selinux_msg_queue_msgsnd & and selinux_msg_queue_msgrcv
kernel: 5.0-rc2
d8c6e85432944 ("msg/security: Pass kern_ipc_perm not msg_queue into the msg_queue security hooks")
appears to have introduced a bug into selinux_msg_queue_msgsnd and selinux_msg_queue_msgrcv
specifically the portion of the patch that does
- isec = msq->q_perm.security;
+ isec = msq->security;
which leaves the code
isec = msq->security; msec = msg->security;
however isec and msec are different size structures. specifically isec is an ipc_security_struct and msec is a msg_security_struct. Which are defined as
struct msg_security_struct {
u32 sid; /* SID of message */
};struct ipc_security_struct {
u16 sclass; /* security class of this object */
u32 sid; /* SID of IPC resource */
};
where the msg->security field is allocated as an ipc_security_struct. Access the msec->sid would thus appear to overlay the isec->sclass.
Paul Moore
maintainerQuoted 12 lines · John Johansen
kernel: 5.0-rc2
d8c6e85432944("msg/security: Passkern_ipc_permnotmsg_queueinto themsg_queuesecurity hooks")appears to have introduced a bug into
selinux_msg_queue_msgsndandselinux_msg_queue_msgrcvspecifically the portion of the patch that does
(quoted diff) +1
-1- isec = msq->q_perm.security; + isec = msq->security;
Quoted 5 lines
which leaves the code
isec = msq->security; msec = msg->security;however isec and msec are different size structures. specifically isec is an
ipc_security_structand msec is amsg_security_struct...
I suspect there may be some mistaken identity regarding "msq" (with a lower-case "Q") and "msg" (with a lower-case "G").
Looking quickly at selinux_msg_queue_msgsnd() and selinux_msg_queue_msgrcv() it would appear that in both cases the kern_ipc_perm->security pointer is assigned to an ipc_security_struct pointer and the msg_msg->security struct is assigned a msg_security_struct pointer. This appears to be correct, or is there something I'm missing in your report?
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 23 lines · Paul Moore
Quoted 12 lines · John Johansen
kernel: 5.0-rc2
d8c6e85432944("msg/security: Passkern_ipc_permnotmsg_queueinto themsg_queuesecurity hooks")appears to have introduced a bug into
selinux_msg_queue_msgsndandselinux_msg_queue_msgrcvspecifically the portion of the patch that does
(quoted diff) +1
-1- isec = msq->q_perm.security; + isec = msq->security;Quoted 5 lines
which leaves the code
isec = msq->security; msec = msg->security;however isec and msec are different size structures. specifically isec is an
ipc_security_structand msec is amsg_security_struct...I suspect there may be some mistaken identity regarding "msq" (with a lower-case "Q") and "msg" (with a lower-case "G").
Quoted 7 lines
Looking quickly at
selinux_msg_queue_msgsnd()andselinux_msg_queue_msgrcv()it would appear that in both cases thekern_ipc_perm->securitypointer is assigned to anipc_security_structpointer and themsg_msg->securitystruct is assigned amsg_security_structpointer. This appears to be correct, or is there something I'm missing in your report?
ha, that is indeed it. I looked at this multiple times and didn't pickup the q vs g. Thanks sorry for the bad report, guess I should have gone to bed sarlier :)
Quoted 22 lines · John Johansen
kernel: 5.0-rc2
d8c6e85432944("msg/security: Passkern_ipc_permnotmsg_queueinto themsg_queuesecurity hooks")appears to have introduced a bug into
selinux_msg_queue_msgsndandselinux_msg_queue_msgrcvspecifically the portion of the patch that does
(quoted diff) +1
-1- isec = msq->q_perm.security; + isec = msq->security;which leaves the code
isec = msq->security; msec = msg->security;however isec and msec are different size structures. specifically isec is an
ipc_security_structand msec is amsg_security_struct. Which are defined asstruct msg_security_struct { u32 sid; /* SID of message */ };
Quoted 6 lines
struct
ipc_security_struct{
u16 sclass; /* security class of this object */
u32 sid; /* SID of IPC resource */
};where the
msg->securityfield is allocated as anipc_security_struct. Access themsec->sidwould thus appear to overlay theisec->sclass.
The only thing that changed in that commit was directly passing &msgq->q_perm to the hook instead of passing msgq to the hook and then dereferencing msq->q_perm to reach the ipc security blob.
msg is a different object from msq with its own security blob (msg is an individual message; msq is the message queue). isec and msec point to two different security blobs with different structures.
I don't see a problem offhand.
Quoted 28 lines · Stephen Smalley
Quoted 27 lines · John Johansen
kernel: 5.0-rc2
d8c6e85432944("msg/security: Passkern_ipc_permnotmsg_queueinto themsg_queuesecurity hooks")appears to have introduced a bug into
selinux_msg_queue_msgsndandselinux_msg_queue_msgrcvspecifically the portion of the patch that does
- isec =
msq->q_perm.security;
+ isec =msq->security;which leaves the code
isec =msq->security;
msec =msg->security;however isec and msec are different size structures. specifically isec is an
ipc_security_structand msec is amsg_security_struct. Which are defined asstruct
msg_security_struct{
u32 sid; /* SID of message */
};struct
ipc_security_struct{
u16 sclass; /* security class of this object */ u32 sid; /* SID of IPC resource */
};
Quoted 7 lines
Quoted 1 line
where the
msg->securityfield is allocated as anipc_security_struct. Access themsec->sidwould thus appear to overlay theisec->sclass.The only thing that changed in that commit was directly passing
&msgq->q_permto the hook instead of passing msgq to the hook and then dereferencingmsq->q_permto reach the ipc security blob.msg is a different object from msq with its own security blob (msg is an individual message; msq is the message queue). isec and msec point to two different security blobs with different structures.
I don't see a problem offhand.
yep, sorry combination of bad fonts, and being 3am. sorry for the bad report