Add kdbus implementation
Subsystems (5)
Hi Eric,
Quoted 7 lines · Eric W. Biederman
The userspace API breaks userspace in an unfixable way.
Problem the first.
- Using global names for containers makes it impossible to create unprivileged containers.
I don't follow.
Just so we are on the same page:
- creating a domain per container is only a convention, and has to
be done manually. I.e., the worst case scenario is that you are able to create some container which cannot get a corresponding kdbus domain.
- domain names are only unique per parent-domain, and domains are
fully recursive. We explicitly tested recursive domains by running kdbus-enabled containers within kdbus-enabled containers, a number of iterations deep.
Could you explain the problem you see in more detail? This might just be a documenation issue, after all.
Quoted 6 lines
This is a back to the drawing board problem, and makes device nodes fundamentally unsuited to what you are doing.
There is no way that I can see to make it safe for an unprivileged user to create arbitrary named busses. Especially in the presence of allowing unprivileged checkpoint/restart.
Note that unprivileged users cannot create arbitrary named busses, the names must have the format $PID-<arbitrary name>. Do you see a problem with this?
Quoted 2 lines
This is particularly bad as kdbus explicitly allows unprivielged creation of new kdbus instances.
What do you mean by kdbus instance? A new domain? This is not allowed by unprivileged processes. Or do you mean a new bus, in which case see above.
Quoted 1 line
This problem is a userspace regression.
This is all new functionality, how does it affect current code?
Quoted 11 lines
Problem the second.
- The security checks in the code are not based on who opens the file descriptors but instead based on who is used the file descriptors at any give moment.That pattern has been shown to be exploitable.
I expect the policy database makes this poor choice of permission checks even worse. Pass a more privileged user a kdbus file descriptor and all of sudden things that were not possible on that file descriptor become possible.
Djalal already commented on this point in another thread. But just to
recap: Please note that we do not do read()/write() at all, only ioctl's, so the most common exploits do not apply. Moreover, we are following the same API pattern as used by other similar APIs in the kernel. With that in mind, could you give some more specific information about what kind of exploits you imagine?
Quoted 6 lines
Problem the third.
- You are using device numbers for things created by unprivileged users. That breaks checkpoint/restart. Aka CRIU.We can not migrate a container to a new machine and preserve the device numbers.
I must admit to not being too familiar with checkpoint/restart. What precisely is the problem with unprivileged users?
Quoted 2 lines
We can not migrate a container to a new machine and have any hope of preserving the container patsh under
/dev/kdbus/...
You may not be able to preserve the full path, no, but the container should not know/care about the parent paths anyway. Note that the containers only see their own domain subtree mounted to /dev/kdbus, they see nothing from the parent. Hence when you migrate containers you can change the naming of the parent freely, but the processes
inside the containers won't see that, they'll have stable paths. I'm
not seeing the problem here, care to elaborate?
Quoted 2 lines
I think a kdbusfs modeled on devpts with newinstance at mount time would solve the naming problems.
Effectively, what we have in place in the current patch set delivers similar semantics, however without introducing a new file system. You just create a new domain and get a new subdir in /dev/kdbus/ for it, and then inside the container you mount that subdir of /dev/kdbus onto /dev/kdbus itself.
Do I understand you correctly that what you want is unnamed/anonymous domains? Considering that domain creation is anyway privileged, why is this necessary?
Quoted 2 lines
That would break one of the current kdbus use cases that allows an unprivileged user to create a bus.
That is a fundamental usecase, so I don't think it makes much sense to do anything that precludes that.
Cheers,
Tom
Quoted 12 lines · Tom Gundersen
Hi Eric,
Quoted 7 lines · Eric W. Biederman
The userspace API breaks userspace in an unfixable way.
Problem the first.
- Using global names for containers makes it impossible to create unprivileged containers.
Quoted 7 lines
I don't follow.
Just so we are on the same page:
- creating a domain per container is only a convention, and has to
be done manually. I.e., the worst case scenario is that you are able to create some container which cannot get a corresponding kdbus domain.
Which is the classic definition of failure to restore a checkpoint. You can't get the name you needed.
Quoted 7 lines
- domain names are only unique per parent-domain, and domains are
fully recursive. We explicitly tested recursive domains by running kdbus-enabled containers within kdbus-enabled containers, a number of iterations deep.Could you explain the problem you see in more detail? This might just be a documenation issue, after all.
Partly there is just a ridiculous amount of complexity in having hiearchical names when there is fundamentally no hierarchy.
The problem I see is that creating a kdbus requires someone to grant you privilege to do it. You have to ask permission from the system administrator. For unprivileged containers you don't have to ask permission to create one, you just need the appropriate support in your kernel.
Given the fact you smash all of the names together in a hierarchy I can't see how you can avoid requiring privilege for part of the hierarchy creation.
Quoted 10 lines
Quoted 6 lines
This is a back to the drawing board problem, and makes device nodes fundamentally unsuited to what you are doing.
There is no way that I can see to make it safe for an unprivileged user to create arbitrary named busses. Especially in the presence of allowing unprivileged checkpoint/restart.
Note that unprivileged users cannot create arbitrary named busses, the names must have the format $PID-<arbitrary name>. Do you see a problem with this?
Yes. What pid namespace is that in?
How do I restore a checkpoint?
Quoted 6 lines
Quoted 2 lines
This is particularly bad as kdbus explicitly allows unprivielged creation of new kdbus instances.
What do you mean by kdbus instance? A new domain? This is not allowed by unprivileged processes. Or do you mean a new bus, in which case see above.
Oh great two concepts domains and busses. The bottom line if I can't create both unprivileged it is a regression in the functionality of unprivileged containers.
Quoted 3 lines
Quoted 1 line
This problem is a userspace regression.
This is all new functionality, how does it affect current code?
If you simply change the existing dbus users to use kdbus you get a regression in containers. Furthermore you get a regression in what kinds of userspace a container can contain.
Quoted 12 lines
Quoted 11 lines
Problem the second.
- The security checks in the code are not based on who opens the file descriptors but instead based on who is used the file descriptors at any give moment.That pattern has been shown to be exploitable.
I expect the policy database makes this poor choice of permission checks even worse. Pass a more privileged user a kdbus file descriptor and all of sudden things that were not possible on that file descriptor become possible.
Quoted 5 lines
Djalal already commented on this point in another thread. But just to
recap: Please note that we do not do read()/write() at all, only ioctl's, so the most common exploits do not apply. Moreover, we are following the same API pattern as used by other similar APIs in the kernel.
A pattern that has led to an exploitable kernel, because it breaks the principle of least surprise.
Quoted 2 lines
With that in mind, could you give some more specific information about what kind of exploits you imagine?
I don't know if it is exploitable or simply a maintenance disaster. But the behavior of file descriptors changing based on who is performing operations on it is wrong. It breaks the common unix expectations.
It means I can not pass a file descriptor into a strongly sandboxed application and be able to predict what can be done with the file descriptor in the sand box.
I suspect what you really want are system calls. As system calls are both less overhead and easier to understand what is going on. Especially for something as commonly used as kdbus is aiming to be ioctls seem like code obfuscation.
The easiest problem to trigger that I can imagine is an application that calls setresuid will have unpredicatable behavior if the change their effective uid happens between one call and the next of your ioctl. Which can create subtle and difficult to find bugs.
There are also all kinds of issues with respect to namespaces that if you care about the namespace you are referring to has to be pinned at open time.
Quoted 13 lines
Quoted 6 lines
Problem the third.
- You are using device numbers for things created by unprivileged users. That breaks checkpoint/restart. Aka CRIU.We can not migrate a container to a new machine and preserve the device numbers.
I must admit to not being too familiar with checkpoint/restart. What precisely is the problem with unprivileged users?
Quoted 2 lines
We can not migrate a container to a new machine and have any hope of preserving the container patsh under
/dev/kdbus/...
Quoted 7 lines
You may not be able to preserve the full path, no, but the container should not know/care about the parent paths anyway. Note that the containers only see their own domain subtree mounted to
/dev/kdbus, they see nothing from the parent. Hence when you migrate containers you can change the naming of the parent freely, but the processes
inside the containers won't see that, they'll have stable paths. I'm
not seeing the problem here, care to elaborate?
Domain creation.
Random path conflicts for no reason except we have two machines.
Quoted 9 lines
Quoted 2 lines
I think a kdbusfs modeled on devpts with newinstance at mount time would solve the naming problems.
Effectively, what we have in place in the current patch set delivers similar semantics, however without introducing a new file system. You just create a new domain and get a new subdir in
/dev/kdbus/for it, and then inside the container you mount that subdir of/dev/kdbusonto/dev/kdbusitself.
Quoted 3 lines
Do I understand you correctly that what you want is unnamed/anonymous domains? Considering that domain creation is anyway privileged, why is this necessary?
When an unprivileged user needs a new domain? If domains are unnamed it is possible that their creation not require privilege.
Anything that requires stopping and asking the system administrator for something so that I can do today with an unprivileged container winds up being a regression, a design bug, and a showstopper.
Unless there is a massive miscommunication you have those kinds of issues with the kbus design.
I would love to hear different but it sounds like domains are a weird partial solution for the fact you have crammed everything into a hierarchy for no good reason.
Quoted 5 lines
Quoted 2 lines
That would break one of the current kdbus use cases that allows an unprivileged user to create a bus.
That is a fundamental usecase, so I don't think it makes much sense to do anything that precludes that.
Eric
Quoted 3 lines · Tom Gundersen
Do I understand you correctly that what you want is unnamed/anonymous domains? Considering that domain creation is anyway privileged, why is this necessary?
As an executive summary, this is the *problem*, not a mitigation. Domain creation *should not require privilege*. You should be able to do it in a user namespace in which you have appropriate capabilities without needing systemd's (or whatever other daemon's) help from outside.
Once you fix that (which may not have broken whatever you tested with but will absolutely break anyone who tries to use this in LXC, Docker, Sandstorm, etc. without awful hacks) then you will have all of the problems that you've currently mitigated.
--Andy
Quoted 6 lines · Greg Kroah-Hartman
* Attachment of trustable metadata to each message on demand, such as the sending peer's timestamp, creds, auxgroups, comm, exe, cmdline, cgroup path, capabilities, security label, audit information, etc, each taken at the time the sender issued the ioctl to send the message. Which of those are actually recorded and attached is controlled by the receiving peer.
I think that each piece of trustable metadata needs to be explicitly opted-in to by the sender at the time of capture. Otherwise you're asking for lots of information leaks and privilege escalations. This is especially important given that some of the items in the current list could be rather sensitive.
NB: UNIX sockets get this wrong, too, but that doesn't mean that kdbus gets to blindly follow SCM_CREDENTIALS's lead. Also, there is no excuse here about legacy code that won't opt in when needed.
--Andy
Greg Kroah-Hartman
maintainerQuoted 9 lines · Andy Lutomirski
Quoted 6 lines · Greg Kroah-Hartman
* Attachment of trustable metadata to each message on demand, such as the sending peer's timestamp, creds, auxgroups, comm, exe, cmdline, cgroup path, capabilities, security label, audit information, etc, each taken at the time the sender issued the ioctl to send the message. Which of those are actually recorded and attached is controlled by the receiving peer.
Quoted 5 lines
I think that each piece of trustable metadata needs to be explicitly opted-in to by the sender at the time of capture. Otherwise you're asking for lots of information leaks and privilege escalations. This is especially important given that some of the items in the current list could be rather sensitive.
You do have to opt-in for this information at time of capture, so I don't understand the issue here. This is the same type of thing that dbus does today, and I don't see the information leaks happening there, do you?
thanks,
greg k-h
Quoted 16 lines · Greg Kroah-Hartman
Quoted 9 lines · Andy Lutomirski
Quoted 6 lines · Greg Kroah-Hartman
* Attachment of trustable metadata to each message on demand, such as the sending peer's timestamp, creds, auxgroups, comm, exe, cmdline, cgroup path, capabilities, security label, audit information, etc, each taken at the time the sender issued the ioctl to send the message. Which of those are actually recorded and attached is controlled by the receiving peer.
Quoted 5 lines
I think that each piece of trustable metadata needs to be explicitly opted-in to by the sender at the time of capture. Otherwise you're asking for lots of information leaks and privilege escalations. This is especially important given that some of the items in the current list could be rather sensitive.
Quoted 5 lines
You do have to opt-in for this information at time of capture, so I don't understand the issue here. This is the same type of thing that dbus does today, and I don't see the information leaks happening there, do you?
The docs suggest that the *receiver* opts in.
I don't think that current dbus has severe information leaks because the total scope for information transparently sent to dbus is rather small (struct ucred only, presumably).
--Andy
Quoted 18 lines · Andy Lutomirski
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Andy Lutomirski
Quoted 6 lines · Greg Kroah-Hartman
* Attachment of trustable metadata to each message on demand, such as the sending peer's timestamp, creds, auxgroups, comm, exe, cmdline, cgroup path, capabilities, security label, audit information, etc, each taken at the time the sender issued the ioctl to send the message. Which of those are actually recorded and attached is controlled by the receiving peer.
I think that each piece of trustable metadata needs to be explicitly opted-in to by the sender at the time of capture. Otherwise you're asking for lots of information leaks and privilege escalations. This is especially important given that some of the items in the current list could be rather sensitive.
Quoted 8 lines
Quoted 5 lines
You do have to opt-in for this information at time of capture, so I don't understand the issue here. This is the same type of thing that dbus does today, and I don't see the information leaks happening there, do you?
The docs suggest that the *receiver* opts in.
So does the code:
+ /*
+ * The first receiver which requests additional
+ * metadata causes the message to carry it; all
+ * receivers after that will see all of the added
+ * data, even when they did not ask for it.
+ */
+ if (conn_src) {
+ /* Check if conn_src is allowed to signal */
+ ret = kdbus_ep_policy_check_broadcast(conn_dst->ep,
+ conn_src,
+ conn_dst);
+ if (ret < 0)
+ continue;
+
+ ret = kdbus_ep_policy_check_src_names(conn_dst->ep,
+ conn_src,
+ conn_dst);
+ if (ret < 0)
+ continue;
+
+ ret = kdbus_kmsg_attach_metadata(kmsg, conn_src,
+ conn_dst);
+ if (ret < 0)
+ goto exit_unlock;
+ }
+
I'd like this if the sender chose the metadata flags. In fact, I'd want to make that feature available on regular UNIX sockets, too (search the archives for SCM_IDENTITY).
--Andy
Quoted 8 lines · Andy Lutomirski
On Wed, Oct 29, 2014 at 3:25 PM, Greg Kroah-Hartman
Quoted 4 lines
You do have to opt-in for this information at time of capture, so I don't understand the issue here. This is the same type of thing that dbus does today, and I don't see the information leaks happening there, do you?
The docs suggest that the *receiver* opts in.
Yes, that's true.
Quoted 3 lines
I don't think that current dbus has severe information leaks because the total scope for information transparently sent to dbus is rather small (struct ucred only, presumably).
Which piece of credential information are you concerned about, particularly? I might miss something, but AFAICS, all of that information can be queried by a remote peer anyway, through /proc for instance. The reason why we (optionally) attach them to messages is that we want to let the other side know which information was authoritative, precisely at the time the message was sent. Current implementation can't do that in a race-free way.
Also note that we currently drop all such metadata whenever a message crosses a PID or user namespace boundary. This is because we currently don't know yet which information we would want to transport in such cases, and how the translation in both directions would look like, from a semantic perspective. Hence, we decided to leave that for later.
I'll go through your other replies during the day. Thanks for your input on that RFC, everyone.
Daniel
Quoted 5 lines · Andy Lutomirski
I think that each piece of trustable metadata needs to be explicitly opted-in to by the sender at the time of capture. Otherwise you're asking for lots of information leaks and privilege escalations. This is especially important given that some of the items in the current list could be rather sensitive.
Alright, the above seems to pretty much sum up that end of our discussion. To address this, We've now added the following functionality for v2:
* The attach_flags in kdbus_cmd_hello was split into two parts, attach_flags_send and attach_flags_recv, so each peer may chose what exactly it want to transmit or receive.
* Metadata will only be attached to the final message in the receiver's pool if both the sender's attach_flags_send and the receiver's attach_flags_recv bit are set.
* Consequently, the existing KDBUS_ITEM_ATTACH_FLAGS item type is split into KDBUS_ITEM_ATTACH_FLAGS_SEND and KDBUS_ITEM_ATTACH_FLAGS_RECV, so that both connection details can be separately updated through KDBUS_CMD_CONN_UPDATE.
* To allow for use cases that require certain metadata to be attached on each message, we've added a negotiation mechanism to the HELLO
ioctl: An optional metadata mask can be passed during the creation of buses, so bus owners may require certain bits in attach_flags_send to be set. That way, the creator of the bus will specify which metadata is required to fulfill the requirements of the specification of the role of the bus.
Thanks again for your input!
Daniel
Quoted 3 lines · Greg Kroah-Hartman
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Greg Kroah-Hartman
maintainerQuoted 9 lines · Jiri Kosina
Quoted 3 lines · Greg Kroah-Hartman
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
Lennart has given whole talks about this in the past, here's a recent talk going into the details:
https://www.youtube.com/watch?v=HPbQzm_iz_k
Quoted 4 lines
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).
We have dbus in userspace today, but that requires extra copies of data, and isn't easy, or even possible, to do some of the application-specific bus logic that kdbus provides. See the talk above for details, there are slides around somewhere with just text that we can add to the cover letter if that will help out in future spins of this patch series.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 20 lines · Greg Kroah-Hartman
Quoted 9 lines · Jiri Kosina
Quoted 3 lines · Greg Kroah-Hartman
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
Lennart has given whole talks about this in the past, here's a recent talk going into the details:
https://www.youtube.com/watch?v=HPbQzm_iz_kQuoted 4 lines
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).
Quoted 5 lines
We have dbus in userspace today, but that requires extra copies of data, and isn't easy, or even possible, to do some of the application-specific bus logic that kdbus provides. See the talk above for details, there are slides around somewhere with just text that we can add to the cover letter if that will help out in future spins of this patch series.
Here's an article describing it as well:
https://lwn.net/Articles/580194/
Quoted 11 lines · Greg Kroah-Hartman
Quoted 7 lines
Quoted 3 lines
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
Lennart has given whole talks about this in the past, here's a recent talk going into the details:
https://www.youtube.com/watch?v=HPbQzm_iz_k
I think it's a reasonable expectation that kernel patch submissions should be reasonably self-contained though. We've always been very strict about pushing everybody to provide extensive cover letters, changelogs and explanations, so this shouldn't really be an exception, I think.
Quoted 6 lines
Quoted 4 lines
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).We have dbus in userspace today, but that requires extra copies of data,
But we can do zero-copy between processess for quite some time already, so what exactly is the issue here?
Quoted 2 lines
and isn't easy, or even possible, to do some of the application-specific bus logic that kdbus provides.
I unfortunately have absolutely no idea what should I imagine here.
Quoted 3 lines
See the talk above for details, there are slides around somewhere with just text that we can add to the cover letter if that will help out in future spins of this patch series.
I think that would be very helpful. Thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 7 lines · Jiri Kosina
Quoted 6 lines
Quoted 4 lines
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).We have dbus in userspace today, but that requires extra copies of data,
Quoted 7 lines
But we can do zero-copy between processess for quite some time already, so what exactly is the issue here?
Quoted 2 lines
and isn't easy, or even possible, to do some of the application-specific bus logic that kdbus provides.
I unfortunately have absolutely no idea what should I imagine here.
Also, I think I have heard that binder is going out of staging now, right?
I admittedly have very limited understanding of both binder and kdbus, but I guess that is the case for many folks. My understanding is that they are providing very similar functionality, so explanation why we need *both* in the kernel would be very interesting as well.
Signature · 2 lines
Jiri Kosina SUSE Labs
Greg Kroah-Hartman
maintainerQuoted 12 lines · Jiri Kosina
Quoted 10 lines · Jiri Kosina
Quoted 6 lines
Quoted 4 lines
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).We have dbus in userspace today, but that requires extra copies of data,
But we can do zero-copy between processess for quite some time already, so what exactly is the issue here?
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
and isn't easy, or even possible, to do some of the application-specific bus logic that kdbus provides.
I unfortunately have absolutely no idea what should I imagine here.
Also, I think I have heard that binder is going out of staging now, right?
Yes, but that needs documentation, which I'm working on at the moment :)
Quoted 4 lines
I admittedly have very limited understanding of both binder and kdbus, but I guess that is the case for many folks. My understanding is that they are providing very similar functionality, so explanation why we need *both* in the kernel would be very interesting as well.
They do very different things, see this writeup I did a while ago about the differences between them:
http://kroah.com/log/blog/2014/01/15/kdbus-details/
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 10 lines · Jiri Kosina
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines
Quoted 3 lines
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
Quoted 8 lines
Quoted 3 lines
Lennart has given whole talks about this in the past, here's a recent talk going into the details:
https://www.youtube.com/watch?v=HPbQzm_iz_kI think it's a reasonable expectation that kernel patch submissions should be reasonably self-contained though. We've always been very strict about pushing everybody to provide extensive cover letters, changelogs and explanations, so this shouldn't really be an exception, I think.
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into, race-free interfaces, container/namespace support, etc.) should be added to the docs as well.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).We have dbus in userspace today, but that requires extra copies of data,
But we can do zero-copy between processess for quite some time already, so what exactly is the issue here?
See the above list for more details.
We'll work on this for the next round of patches, thanks.
greg k-h
Quoted 20 lines · Greg Kroah-Hartman
Quoted 10 lines · Jiri Kosina
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines
Quoted 3 lines
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
Quoted 8 lines
Quoted 3 lines
Lennart has given whole talks about this in the past, here's a recent talk going into the details:
https://www.youtube.com/watch?v=HPbQzm_iz_kI think it's a reasonable expectation that kernel patch submissions should be reasonably self-contained though. We've always been very strict about pushing everybody to provide extensive cover letters, changelogs and explanations, so this shouldn't really be an exception, I think.
Quoted 7 lines
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into, race-free interfaces, container/namespace support, etc.) should be added to the docs as well.
It's worth noting that:
- Proper credential passing could be added to UNIX sockets, and we
may want to do that anyway. Also, the current kdbus semantics seem to be "spew lots of credentials and other miscellaneous potentially-sensitive and sometime spoofable information all over the place", which isn't obviously an improvement. (This is fixable, but it will almost certainly not be compatible with current systemd kdbus code if fixed.)
- The current kdbus patches seem to be worse than UNIX sockets from a
namespace perspective, but maybe I'm misunderstanding how it's supposed to work. UNIX sockets work quite nicely in containers.
- There's an obvious interface to add timestamping to UNIX sockets
(it could work exactly the way it does for UDP / PTP).
- I'm unconvinced by this performance argument without numbers. The
kdbus credential code, at least, looks to be quite heavy on allocation and atomics. This isn't to say that the current userspace D-Bus daemon doesn't also serialize everything, but it could be made multithreaded.
- Race-free? What are the races that are inherent to UNIX sockets?
--Andy
On 10/30/2014 12:55 AM, Andy Lutomirski wrote:> It's worth noting that:
Quoted 8 lines
- Proper credential passing could be added to UNIX sockets, and we
may want to do that anyway. Also, the current kdbus semantics seem to be "spew lots of credentials and other miscellaneous potentially-sensitive and sometime spoofable information all over the place", which isn't obviously an improvement. (This is fixable, but it will almost certainly not be compatible with current systemd kdbus code if fixed.)
Care to elaborate on what you think is spoofable, and what needs to be fixed?
Anyway, the idea is that by simply connecting to the bus and sending a message to some service, you implicitly agree to passing some metadata along to the service (and to a lesser extent to the bus). It's not that this information is leaked, or that the peer could actively access any of the sender's private memory. Also note that this kind of metadata information is also available via /proc/$PID, and via SCM_CREDENTIALS/SO_PEERCRED and the socket seclabel APIs. What the kdbus API allows users to do is to get a lot more of this information in a race-free way. For example, if you want to get the audit identity bits, you can now get this attached securely by the kernel, at the time the message is sent, rather than having to firest get the peer's $PID from SCM_CREDENTIALS and then read the audit identity bits racily from /proc/$PID/loginuid and /proc/$PID/sessionid.
Quoted 3 lines
- The current kdbus patches seem to be worse than UNIX sockets from a
namespace perspective, but maybe I'm misunderstanding how it's supposed to work. UNIX sockets work quite nicely in containers.
kdbus is recusively stackable for containers. You can run kdbus-enabled containers within kdbus-enabled containers within kdbus-enabled containers, with the full functionality available for each container, and each container isolated from each other.
When credential information is passed between processes of different (PID) namespaces most of the attached metadata is suppressed. This isn't too different from how SCM_CREDENTIALS works, which will zero out the bits it cannot translate as well.
Quoted 2 lines
- There's an obvious interface to add timestamping to UNIX sockets
(it could work exactly the way it does for UDP / PTP).
Timestamping on AF_UNIX/SOCK_DGRAM already exists, but that's not enough for the use-cases we want to support.
Quoted 5 lines
- I'm unconvinced by this performance argument without numbers. The
kdbus credential code, at least, looks to be quite heavy on allocation and atomics. This isn't to say that the current userspace D-Bus daemon doesn't also serialize everything, but it could be made multithreaded.
There are some major benefits regarding performance:
* fewer userspace context switches. For a full-duplex method call it's down from five to two: instead of sender -> dbus daemon -> service -> dbus daemon -> sender it's just sender -> service -> sender.
* fewer message copies in userspace. For a full-duplex method call it's down from eight to two: instead of copying the method call data into a socket, out of a socket, into a socket, out of a socket, and the same for the method reply, we just copy one message directly to the receiver, and the reply back.
* generally fewer syscalls involved. A synchronous method call is now doable in a single ioctl on the sender side.
* memfds can be used for transport purposes of larger payload. This way, we can cover substantial payload sizes instead of just small control messages, with no extra copies. kdbus, in its transport layer, makes sure only sealed memfds are passed in as payload, so the sender cannot modify the contents while the receiver is already parsing it.
Quoted 1 line
- Race-free? What are the races that are inherent to UNIX sockets?
Does the above explain what we have in mind?
Note that the aim is not necessarily that kdbus should be better than UNIX sockets in every way, nor that it should be favoured in all cases. What we are trying to address is a common case in environments where peers don't necessarily trust each other.
Cheers,
Tom
Quoted 5 lines · Tom Gundersen
For example, if you want to get the audit identity
bits, you can now get this attached securely by the kernel, at the time the message is sent, rather than having to firest get the peer's $PID fromSCM_CREDENTIALSand then read the audit identity bits racily from/proc/$PID/loginuidand/proc/$PID/sessionid
... which dbus-daemon (traditional D-Bus) deliberately doesn't offer as a feature, because we are not aware of any way to do that over Unix sockets without a race condition; and if we can't have it securely, we don't want to have it at all.
<https://bugs.freedesktop.org/show_bug.cgi?id=83499>
It would be great if kdbus can fix that omission.
Capabilities are in the same boat, and as a result, systemd can't currently have D-Bus methods that can only be called with CAP_WHATEVER.
Quoted 1 line
* fewer userspace context switches
[...]
Quoted 1 line
* fewer message copies in userspace
Readers are probably already aware of this, but note that D-Bus is designed to be usable between mutually distrusting processes, which is why we use Unix sockets and a lot of copies, rather than mmap or something.
S
Quoted 11 lines · Tom Gundersen
On 10/30/2014 12:55 AM, Andy Lutomirski wrote:> It's worth noting that:
Quoted 8 lines
- Proper credential passing could be added to UNIX sockets, and we
may want to do that anyway. Also, the current kdbus semantics seem to be "spew lots of credentials and other miscellaneous potentially-sensitive and sometime spoofable information all over the place", which isn't obviously an improvement. (This is fixable, but it will almost certainly not be compatible with current systemd kdbus code if fixed.)Care to elaborate on what you think is spoofable, and what needs to be fixed?
cmd and comm are trivially replaceable by any sender.
Quoted 6 lines
Anyway, the idea is that by simply connecting to the bus and sending a message to some service, you implicitly agree to passing some metadata along to the service (and to a lesser extent to the bus). It's not that this information is leaked, or that the peer could actively access any of the sender's private memory.
To me, this smells like bad design. By using kdbus, I implicitly agree to send everyone my command line?!? If I'm in a cgroup that policy decrees should be privileged, then I should invoke that privilege by specifically asking, *at the time of capture*, to send that cgroup. Otherwise it becomes unclear what things convey privilege when, and that will lead immediately to incomprehensible security models, and that will lead to exploits.
<snark>Sorry, but "implicitly agree" sounds a lot like using my esteemed cellphone carrier. When I use it, some argue that I implicitly agree to have my identity prepended to all outgoing HTTP requests. This is *not* a good thing.</snark>
Quoted 3 lines
Also note that this kind of
metadata information is also available via/proc/$PID, and via SCM_CREDENTIALS/SO_PEERCRED and the socket seclabel APIs.
Not if you have a sensible LSM policy or if you use hidepid. And, once you've fixed the namespacing issues, not if the sender and receiver are in different PID namespaces or if they don't have /proc mounted at all.
Quoted 3 lines
When credential information is passed between processes of different (PID) namespaces most of the attached metadata is suppressed.
This is a bug. It prevents users from usefully sandboxing themselves in a kdbus world. If you create and enter a user namespace, then your outside identity (which should be unchanged) is suppressed. (Note that anything that captures credentials other than at open time is also an issue for sandboxes in the other direction: it may interfere with selective privilege dropping.)
Quoted 3 lines
This
isn't too different from howSCM_CREDENTIALSworks, which will zero out the bits it cannot translate as well.
SCM_CREDENTIALS translates the translatable parts.
Quoted 17 lines
There are some major benefits regarding performance:
* fewer userspace context switches. For a full-duplex method call it's down from five to two: instead of sender -> dbus daemon -> service -> dbus daemon -> sender it's just sender -> service -> sender.
* fewer message copies in userspace. For a full-duplex method call it's down from eight to two: instead of copying the method call data into a socket, out of a socket, into a socket, out of a socket, and the same for the method reply, we just copy one message directly to the receiver, and the reply back.
* generally fewer syscalls involved. A synchronous method call is now doable in a single ioctl on the sender side.
* memfds can be used for transport purposes of larger payload. This way, we can cover substantial payload sizes instead of just small control messages, with no extra copies. kdbus, in its transport layer, makes sure only sealed memfds are passed in as payload, so the sender cannot modify the contents while the receiver is already parsing it.
There should be a number measured in, say, nanoseconds in here somewhere. The actual extent of the speedup is unmeasurable here. Also, it's worth reading at least one of Linus' many rants about zero-copy. It's not an automatic win.
--Andy
Andy Lutomirski wrote:
<snip>
Quoted 4 lines
There should be a number measured in, say, nanoseconds in here somewhere. The actual extent of the speedup is unmeasurable here. Also, it's worth reading at least one of Linus' many rants about zero-copy. It's not an automatic win.
It's well-understood that it's not an automatic win; significant testing on multiple architectures indicated that 512K is a surprisingly universal crossover point. The userspace code, therefore, switches from copying (normal kdbus parameters) to zero-copy (memfds) right around there.
Quoted 5 lines · Greg Kroah-Hartman
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into
While you're at it... I have worked on proof-of-concept LSM patches for kdbus some time ago, see [1][2]. Currently, these are completely of date.
[1] https://github.com/lmctl/linux/commits/kdbus-lsm-v4.for-systemd-v212
[2] https://github.com/lmctl/kdbus/commit/aa0885489d19be92fa41c6f0a71df28763228a40
May I ask if you guys have your own plan for LSM or maybe it would be worth to resurrect [1]?
Cheers,
Signature · 1 line
Karol Lewandowski, Samsung R&D Institute Poland
[ Sorry for breaking thread and resend - gmane rejected my original message
due to too long list of recipients... ]
Quoted 5 lines · Greg Kroah-Hartman
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into
While you're at it... I did some work on proof-of-concept LSM patches for kdbus some time ago, see [1][2]. Currently, these are completely of date.
[1] https://github.com/lmctl/linux/commits/kdbus-lsm-v4.for-systemd-v212
[2] https://github.com/lmctl/kdbus/commit/aa0885489d19be92fa41c6f0a71df28763228a40
May I ask if you guys have your own plan for LSM or maybe it would be worth to resurrect [1]?
Cheers,
Signature · 1 line
Karol Lewandowski, Samsung R&D Institute Poland
Greg Kroah-Hartman
maintainerQuoted 11 lines · Karol Lewandowski
[ Sorry for breaking thread and resend - gmane rejected my original message
due to too long list of recipients... ]Quoted 5 lines · Greg Kroah-Hartman
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into
Quoted 8 lines
While you're at it... I did some work on proof-of-concept LSM patches for kdbus some time ago, see [1][2]. Currently, these are completely of date.
[1] https://github.com/lmctl/linux/commits/kdbus-lsm-v4.for-systemd-v212
[2] https://github.com/lmctl/kdbus/commit/aa0885489d19be92fa41c6f0a71df28763228a40May I ask if you guys have your own plan for LSM or maybe it would be worth to resurrect [1]?
The core calls are already mediated by LSM today, right? We don't want anyone to be parsing the data stream through an LSM, that idea got rejected a long time ago as something that is really not a good idea.
Other than that, I don't know exactly what your patches do, or why they are needed, care to go into details?
thanks,
greg k-h
Quoted 18 lines · Greg Kroah-Hartman
Quoted 17 lines · Karol Lewandowski
[ Sorry for breaking thread and resend - gmane rejected my original message
due to too long list of recipients... ]Quoted 5 lines · Greg Kroah-Hartman
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into
While you're at it... I did some work on proof-of-concept LSM patches for kdbus some time ago, see [1][2]. Currently, these are completely of date.
[1] https://github.com/lmctl/linux/commits/kdbus-lsm-v4.for-systemd-v212
[2] https://github.com/lmctl/kdbus/commit/aa0885489d19be92fa41c6f0a71df28763228a40
Quoted 6 lines
Quoted 2 lines
May I ask if you guys have your own plan for LSM or maybe it would be worth to resurrect [1]?
The core calls are already mediated by LSM today, right? We don't want anyone to be parsing the data stream through an LSM, that idea got rejected a long time ago as something that is really not a good idea.
Parsing data is out of question, of course, but this is not what we were proposing.
Quoted 2 lines
Other than that, I don't know exactly what your patches do, or why they are needed, care to go into details?
Patches in question were supposed to add few hooks for kdbus-specific operations that doesn't seem to have compatible semantics with hooks currently available in LSM.
kdbus' bus introduces quite a few new concepts that we wanted to be able to limit based on MAC label/context, eg.
- check flags at HELO stage (say disallow fd passing),
- restrict ability to acquire name to certain subjects (for system bus),
- disallow creation of new buses,
- limit scope of broadcasts,
- etc.
Please take a look at hook list - I think most of names are self-explanatory:
kdbus modifications were pretty light - with most visible change being addition of opaque security pointer to kdbus_bus and similar structs.
Thanks!
Signature · 1 line
Karol Lewandowski, Samsung R&D Institute Poland
Greg Kroah-Hartman
maintainerQuoted 22 lines · Karol Lewandowski
Quoted 21 lines · Greg Kroah-Hartman
Quoted 19 lines · Karol Lewandowski
[ Sorry for breaking thread and resend - gmane rejected my original message
due to too long list of recipients... ]Quoted 5 lines · Greg Kroah-Hartman
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into
While you're at it... I did some work on proof-of-concept LSM patches for kdbus some time ago, see [1][2]. Currently, these are completely of date.
[1] https://github.com/lmctl/linux/commits/kdbus-lsm-v4.for-systemd-v212
[2] https://github.com/lmctl/kdbus/commit/aa0885489d19be92fa41c6f0a71df28763228a40May I ask if you guys have your own plan for LSM or maybe it would be worth to resurrect [1]?
Quoted 6 lines
Quoted 3 lines
The core calls are already mediated by LSM today, right? We don't want anyone to be parsing the data stream through an LSM, that idea got rejected a long time ago as something that is really not a good idea.
Parsing data is out of question, of course, but this is not what we were proposing.
Glad to hear it :)
Quoted 12 lines
Quoted 2 lines
Other than that, I don't know exactly what your patches do, or why they are needed, care to go into details?
Patches in question were supposed to add few hooks for kdbus-specific operations that doesn't seem to have compatible semantics with hooks currently available in LSM.
kdbus' bus introduces quite a few new concepts that we wanted to be able to limit based on MAC label/context, eg.
- check flags at HELO stage (say disallow fd passing),
Quoted 7 lines
- restrict ability to acquire name to certain subjects (for system bus),
- disallow creation of new buses,
- limit scope of broadcasts,
- etc.
Nice list.
Quoted 6 lines
Please take a look at hook list - I think most of names are self-explanatory:
kdbus modifications were pretty light - with most visible change being addition of opaque security pointer to
kdbus_busand similar structs.
That looks very reasonable, care to make it up into a patch I can add to the end of this series so it's easy to review and possibly submit as part of it?
thanks,
greg k-h
Quoted 56 lines · Greg Kroah-Hartman
Quoted 22 lines · Karol Lewandowski
Quoted 21 lines · Greg Kroah-Hartman
Quoted 19 lines · Karol Lewandowski
[ Sorry for breaking thread and resend - gmane rejected my original message
due to too long list of recipients... ]Quoted 5 lines · Greg Kroah-Hartman
There is a 1815 line documentation file in this series, so we aren't trying to not provide this type of information here at all. But yes, more background, about why this can't be done in userspace (zero copy, less context switches, proper credential passing, timestamping, availble at early-boot, LSM hooks for security models to tie into
While you're at it... I did some work on proof-of-concept LSM patches for kdbus some time ago, see [1][2]. Currently, these are completely of date.
[1] https://github.com/lmctl/linux/commits/kdbus-lsm-v4.for-systemd-v212
[2] https://github.com/lmctl/kdbus/commit/aa0885489d19be92fa41c6f0a71df28763228a40May I ask if you guys have your own plan for LSM or maybe it would be worth to resurrect [1]?
Quoted 6 lines
Quoted 3 lines
The core calls are already mediated by LSM today, right? We don't want anyone to be parsing the data stream through an LSM, that idea got rejected a long time ago as something that is really not a good idea.
Parsing data is out of question, of course, but this is not what we were proposing.
Glad to hear it :)
Quoted 12 lines
Quoted 2 lines
Other than that, I don't know exactly what your patches do, or why they are needed, care to go into details?
Patches in question were supposed to add few hooks for kdbus-specific operations that doesn't seem to have compatible semantics with hooks currently available in LSM.
kdbus' bus introduces quite a few new concepts that we wanted to be able to limit based on MAC label/context, eg.
- check flags at HELO stage (say disallow fd passing),
Quoted 7 lines
- restrict ability to acquire name to certain subjects (for system bus),
- disallow creation of new buses,
- limit scope of broadcasts,
- etc.
Nice list.
Quoted 2 lines
Please take a look at hook list - I think most of names are self-explanatory:
Quoted 8 lines
Quoted 4 lines
kdbus modifications were pretty light - with most visible change being addition of opaque security pointer to
kdbus_busand similar structs.That looks very reasonable, care to make it up into a patch I can add to the end of this series so it's easy to review and possibly submit as part of it?
I'll do my best to prepare something suitable for review, but I'm not sure it can/should be part of next patch set.
As Paul wrote - discussion about hooks hasn't really ended up with satisfactory conclusion but just faded away. kdbus own policy engine has been rewritten since I last touched it so I'm not sure what part are still applicable.
(Unfortunately, I'll be traveling from monday and likely to be offline for a week or two...)
Thanks
Signature · 1 line
Karol Lewandowski, Samsung R&D Institute Poland
Quoted 6 lines
Quoted 3 lines
The core calls are already mediated by LSM today, right? We don't want anyone to be parsing the data stream through an LSM, that idea got rejected a long time ago as something that is really not a good idea.
Parsing data is out of question, of course, but this is not what we were proposing.
Why is it out of the question. If it's a socket you can just a BPF filter on it, so why can't kdbus support similar basic functionality ?
Alan
Quoted 9 lines · One Thousand Gnomes
Quoted 6 lines
Quoted 3 lines
The core calls are already mediated by LSM today, right? We don't want anyone to be parsing the data stream through an LSM, that idea got rejected a long time ago as something that is really not a good idea.
Parsing data is out of question, of course, but this is not what we were proposing.
Why is it out of the question. If it's a socket you can just a BPF filter on it, so why can't kdbus support similar basic functionality ?
Fair point. I think that none of us simply considered this till now.
Thanks
Signature · 1 line
Karol Lewandowski, Samsung R&D Institute Poland
Quoted 25 lines · Karol Lewandowski
Quoted 2 lines · Greg Kroah-Hartman
Other than that, I don't know exactly what your patches do, or why they are needed, care to go into details?
Patches in question were supposed to add few hooks for kdbus-specific operations that doesn't seem to have compatible semantics with hooks currently available in LSM.
kdbus' bus introduces quite a few new concepts that we wanted to be able to limit based on MAC label/context, eg.
- check flags at HELO stage (say disallow fd passing),
- restrict ability to acquire name to certain subjects (for system bus),
- disallow creation of new buses,
- limit scope of broadcasts,
- etc.
Please take a look at hook list - I think most of names are self-explanatory:
Quoted 5 lines
https://github.com/lmctl/linux/blob/a9fe4c33b6e5ab25a243e0590df406aabb6add1
2/include/linux/security.h#L1874kdbus modifications were pretty light - with most visible change being addition of opaque security pointer to
kdbus_busand similar structs.
[NOTE: we really should add the LSM list to this discussion and future patchset postings.]
Also, to be completely honest, I don't think we ever really arrived at any final conclusion about those LSM/kdbus hooks either. At least I don't think I ever really satisfied myself that what we had was the "right" solution.
We both got busy and kinda drifted away from this effort. Karol, did you do any further work on the hooks?
Signature · 2 lines
paul moore security and virtualization @ redhat
Quoted 32 lines · Paul Moore
Quoted 25 lines · Karol Lewandowski
Quoted 2 lines · Greg Kroah-Hartman
Other than that, I don't know exactly what your patches do, or why they are needed, care to go into details?
Patches in question were supposed to add few hooks for kdbus-specific operations that doesn't seem to have compatible semantics with hooks currently available in LSM.
kdbus' bus introduces quite a few new concepts that we wanted to be able to limit based on MAC label/context, eg.
- check flags at HELO stage (say disallow fd passing),
- restrict ability to acquire name to certain subjects (for system bus),
- disallow creation of new buses,
- limit scope of broadcasts,
- etc.
Please take a look at hook list - I think most of names are self-explanatory:
Quoted 5 lines
https://github.com/lmctl/linux/blob/a9fe4c33b6e5ab25a243e0590df406aabb6add1
2/include/linux/security.h#L1874kdbus modifications were pretty light - with most visible change being addition of opaque security pointer to
kdbus_busand similar structs.
Quoted 6 lines
[NOTE: we really should add the LSM list to this discussion and future patchset postings.]
Also, to be completely honest, I don't think we ever really arrived at any final conclusion about those LSM/kdbus hooks either. At least I don't think I ever really satisfied myself that what we had was the "right" solution.
Agreed, "hooks" are far from being complete. I think that patches were and still are - a starting point for discussion, not "a solution" itself.
Timing wasn't good either - since our last discussion (Apr/May 2014) kdbus policy engine has been completely rewritten and few core concepts changed too.
Quoted 2 lines
We both got busy and kinda drifted away from this effort. Karol, did you do any further work on the hooks?
I didn't. I was waiting for the peace of change in kdbus to slow down a bit and, honestly, wasn't expecting submission in few next months...
I'll do my best to post RFC patchset today or tomorrow.
Thanks
Signature · 1 line
Karol Lewandowski, Samsung R&D Institute Poland
cover kdbus: add support for lsm
This is set of EXPERIMENTAL patches adding lsm support to kdbus. (Rebased on top of v3.17.)
Quoted 1 line
From least to most invasive:
- (1) kdbus: extend structures with security pointer for lsm
Trivial. Applicable as-is.
- (2) security: export security_file_receive for modules
(3) kdbus: check if lsm permits installing received fds
fd_install doesn't seem to consult LSM, these patches ensure that receiving process has the right to sent fds.
Compile-tested only.
- (4) security: introduce lsm hooks for kdbus
(5) kdbus: make use of new lsm hooks
Set of proof-of-concept hooks discussed previously with Paul Moore.
kdbus integration patch (5) for review, but unlikely for integration at this stage.
Likewise, compile-tested only.
Karol Lewandowski (5):
kdbus: extend structures with security pointer for lsm
security: export security_file_receive for modules
kdbus: check if lsm permits installing received fds
security: introduce lsm hooks for kdbus
kdbus: make use of new lsm hooks
drivers/misc/kdbus/bus.c | 10 +++- drivers/misc/kdbus/bus.h | 2 + drivers/misc/kdbus/connection.c | 34 +++++++++++- drivers/misc/kdbus/connection.h | 2 + drivers/misc/kdbus/domain.c | 7 +++ drivers/misc/kdbus/domain.h | 2 + drivers/misc/kdbus/endpoint.c | 11 ++++ drivers/misc/kdbus/names.c | 9 ++++ drivers/misc/kdbus/queue.c | 13 +++++ include/linux/security.h | 114 ++++++++++++++++++++++++++++++++++++++++ security/capability.c | 84 +++++++++++++++++++++++++++++ security/security.c | 85 ++++++++++++++++++++++++++++++ 12 files changed, 371 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.1
PATCH 1/5 kdbus: extend structures with security pointer for lsm
--- drivers/misc/kdbus/bus.h | 2 ++ drivers/misc/kdbus/connection.h | 2 ++ drivers/misc/kdbus/domain.h | 2 ++ 3 files changed, 6 insertions(+)
drivers/misc/kdbus/bus.h +2 -0
@@ -49,6 +49,7 @@* @conn_hash: Map of connection IDs * @monitors_list: Connections that monitor this bus * @meta: Meta information about the bus creator +* @security: LSM security blob * * A bus provides a "bus" endpoint / device node. *
@@ -84,6 +85,7 @@ struct kdbus_bus {struct list_head monitors_list;struct kdbus_meta *meta; +void *security; }; int kdbus_bus_make_user(const struct kdbus_cmd_make *make,
drivers/misc/kdbus/connection.h +2 -0
@@ -64,6 +64,7 @@* waits for replies from the peer * @wait: Wake up this endpoint * @queue: The message queue associcated with this connection +* @security: LSM security blob */ struct kdbus_conn {struct kref kref;
@@ -98,6 +99,7 @@ struct kdbus_conn {atomic_t reply_count;wait_queue_head_t wait;struct kdbus_queue queue; +void *security; };struct kdbus_kmsg ;
drivers/misc/kdbus/domain.h +2 -0
@@ -35,6 +35,7 @@* @bus_list: Buses in this domain * @user_hash: Accounting of user resources * @user_idr: Map of all users; smallest possible index +* @security: LSM security blob * * A domain provides a "control" device node. Every domain has its * own major number for its endpoint device nodes.
@@ -62,6 +63,7 @@ struct kdbus_domain {struct list_head bus_list;DECLARE_HASHTABLE (user_hash,6 );struct idr user_idr; +void *security; };/**
Signature · 1 line
2.1.1
Re: [PATCH 1/5] kdbus: extend structures with security pointer for lsm
Quoted 20 lines · Karol Lewandowski
Signed-off-by Karol Lewandowski <[email protected]>--- drivers/misc/kdbus/bus.h | 2 ++ drivers/misc/kdbus/connection.h | 2 ++ drivers/misc/kdbus/domain.h | 2 ++ 3 files changed, 6 insertions(+)drivers/misc/kdbus/bus.h +1
-0@@ -49,6 +49,7 @@* @conn_hash: Map of connection IDs * @monitors_list: Connections that monitor this bus * @meta: Meta information about the bus creator +* @security: LSM security blob * * A bus provides a "bus" endpoint / device node. *
drivers/misc/kdbus/bus.h struct kdbus_bus { · line 88
Quoted 4 lines
drivers/misc/kdbus/bus.h +1
-0@@ -84,6 +85,7 @@ struct kdbus_bus {struct list_head monitors_list;struct kdbus_meta *meta; +void *security;
One minor note - with possibility of LSM modules trying to access these structures it would be worth to have kdbus headers in, say include/linux/kdbus or similar globally accessible location.
Thanks
Greg KH
maintainerRe: [PATCH 1/5] kdbus: extend structures with security pointer for lsm
Quoted 23 lines · Karol Lewandowski
Quoted 22 lines · Karol Lewandowski
Signed-off-by Karol Lewandowski <[email protected]>--- drivers/misc/kdbus/bus.h | 2 ++ drivers/misc/kdbus/connection.h | 2 ++ drivers/misc/kdbus/domain.h | 2 ++ 3 files changed, 6 insertions(+)drivers/misc/kdbus/bus.h +1
-0@@ -49,6 +49,7 @@* @conn_hash: Map of connection IDs * @monitors_list: Connections that monitor this bus * @meta: Meta information about the bus creator +* @security: LSM security blob * * A bus provides a "bus" endpoint / device node. * @@ -84,6 +85,7 @@ struct kdbus_bus {struct list_head monitors_list;
Quoted 6 lines
drivers/misc/kdbus/bus.h struct kdbus_bus { · line 88
Quoted 2 lines
drivers/misc/kdbus/bus.h +1
-0struct kdbus_meta *meta; +void *security;One minor note - with possibility of LSM modules trying to access these structures it would be worth to have kdbus headers in, say
include/linux/kdbusor similar globally accessible location.
Yes, that is a good idea.
PATCH 2/5 security: export security_file_receive for modules
In reply to Karol LewandowskiThis is required for kdbus built as module.
--- security/security.c | 1 + 1 file changed, 1 insertion(+)
security/security.c +1 -0
@@ -790,6 +790,7 @@ int security_file_receive(struct file *file) {return security_ops->file_receive (file); } +EXPORT_SYMBOL (security_file_receive);int security_file_open (struct file *file,const struct cred *cred) {
Signature · 1 line
2.1.1
PATCH 3/5 kdbus: check if lsm permits installing received fds
In reply to Karol LewandowskiFrom: Karol Lewandowski <[email protected]>
--- drivers/misc/kdbus/queue.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/misc/kdbus/queue.c +13 -0
@@ -25,6 +25,7 @@#include <linux/poll.h> #include <linux/sched.h> #include <linux/sizes.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/syscalls.h>
@@ -41,6 +42,18 @@ static int kdbus_queue_entry_fds_install(struct kdbus_queue_entry *entry)int ret, *fds;size_t count; +for (i =0 ; i < entry->fds_count; i++) { + ret =security_file_receive (entry->fds_fp[i]); +if (ret) +return ret; + } + +for (i =0 ; i < entry->memfds_count; i++) { + ret =security_file_receive (entry->memfds_fp[i]); +if (ret) +return ret; + } +/* get array of file descriptors */ count = entry->fds_count + entry->memfds_count;if (!count)
Signature · 1 line
2.1.1
A message that is not in the archive (sent off-list or not yet received): 1414773397-26490-1-git-send-email-k.lewandowsk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
PATCH 3/5 kdbus: check if lsm permits installing received fds
From: Karol Lewandowski <[email protected]>
--- drivers/misc/kdbus/queue.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/misc/kdbus/queue.c +13 -0
@@ -25,6 +25,7 @@#include <linux/poll.h> #include <linux/sched.h> #include <linux/sizes.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/syscalls.h>
@@ -41,6 +42,18 @@ static int kdbus_queue_entry_fds_install(struct kdbus_queue_entry *entry)int ret, *fds;size_t count; +for (i =0 ; i < entry->fds_count; i++) { + ret =security_file_receive (entry->fds_fp[i]); +if (ret) +return ret; + } + +for (i =0 ; i < entry->memfds_count; i++) { + ret =security_file_receive (entry->memfds_fp[i]); +if (ret) +return ret; + } +/* get array of file descriptors */ count = entry->fds_count + entry->memfds_count;if (!count)
Signature · 1 line
2.1.1
PATCH 4/5 security: introduce lsm hooks for kdbus
In reply to a message not in the archiveThis is proof-of-concept set of hooks for kdbus by Karol Lewandowski and Paul Moore.
--- include/linux/security.h | 114 +++++++++++++++++++++++++++++++++++++++++++++++ security/capability.c | 84 ++++++++++++++++++++++++++++++++++ security/security.c | 84 ++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+)
include/linux/security.h +114 -0
@@ -53,6 +53,10 @@ struct msg_queue;struct xattr ;struct xfrm_sec_ctx ;struct mm_struct ; +struct kdbus_ep ; +struct kdbus_bus ; +struct kdbus_conn ; +struct kdbus_domain ;/* Maximum number of letters for an LSM name string */ #define SECURITY_NAME_MAX 10
@@ -1438,6 +1442,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @ctxlen points to the place to put the length of @ctx. * This is the main security structure. */ +/* XXX - need to include descriptions for the kdbus hooks in the block above */ struct security_operations {char name[SECURITY_NAME_MAX +1 ];
@@ -1645,6 +1650,24 @@ struct security_operations {int (*inode_setsecctx)(struct dentry *dentry,void *ctx,u32 ctxlen);int (*inode_getsecctx)(struct inode *inode,void **ctx,u32 *ctxlen); +int (*kdbus_domain_alloc)(struct kdbus_domain *domain); +void (*kdbus_domain_free)(struct kdbus_domain *domain); + +int (*kdbus_bus_alloc)(struct kdbus_bus *bus); +void (*kdbus_bus_free)(struct kdbus_bus *bus); +int (*kdbus_send)(const struct kdbus_conn *conn,const struct kdbus_bus *bus); +int (*kdbus_recv)(const struct kdbus_conn *conn,const struct kdbus_bus *bus); +int (*kdbus_name_acquire)(const struct kdbus_conn *conn,const char *name); +int (*kdbus_name_list)(const struct kdbus_bus *bus); + +int (*kdbus_ep_create)(const struct kdbus_bus *bus); +int (*kdbus_ep_setpolicy)(const struct kdbus_bus *bus); + +int (*kdbus_connect)(struct kdbus_conn *conn,const char *secctx,u32 seclen); +void (*kdbus_conn_free)(struct kdbus_conn *conn); +int (*kdbus_conn_info)(const struct kdbus_conn *conn); +int (*kdbus_talk)(const struct kdbus_conn *src,const struct kdbus_conn *dst); +#ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect) (struct sock *sock,struct sock *other,struct sock *newsk);int (*unix_may_send) (struct socket *sock,struct socket *other);
@@ -1905,6 +1928,25 @@ void security_release_secctx(char *secdata, u32 seclen);int security_inode_notifysecctx (struct inode *inode,void *ctx,u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen);int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen); + +int security_kdbus_domain_alloc (struct kdbus_domain *domain); +void security_kdbus_domain_free (struct kdbus_domain *domain); + +int security_kdbus_bus_alloc (struct kdbus_bus *bus); +void security_kdbus_bus_free (struct kdbus_bus *bus); +int security_kdbus_send (const struct kdbus_conn *conn,const struct kdbus_bus *bus); +int security_kdbus_recv (const struct kdbus_conn *conn,const struct kdbus_bus *bus); +int security_kdbus_name_acquire (const struct kdbus_conn *conn,const char *name); +int security_kdbus_name_list (const struct kdbus_bus *bus); + +int security_kdbus_ep_create (struct kdbus_bus *bus); +int security_kdbus_ep_setpolicy (struct kdbus_bus *bus); + +int security_kdbus_connect (struct kdbus_conn *conn,const char *secctx,u32 seclen); +void security_kdbus_conn_free (struct kdbus_conn *conn); +int security_kdbus_conn_info (const struct kdbus_conn *conn); +int security_kdbus_talk (const struct kdbus_conn *src,const struct kdbus_conn *dst); +#else /* CONFIG_SECURITY */ struct security_mnt_opts { };
@@ -2630,6 +2672,78 @@ static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 {return -EOPNOTSUPP ; } + +static inline int security_kdbus_domain_alloc (struct kdbus_domain *domain) +{ +return 0 ; +} +static inline void security_kdbus_domain_free (struct kdbus_domain *domain) +{ +} + +static inline int security_kdbus_bus_alloc (struct kdbus_bus *bus) +{ +return 0 ; +} + +static inline void security_kdbus_bus_free (struct kdbus_bus *bus) +{ +} + +static inline int security_kdbus_send (const struct kdbus_conn *conn, +const struct kdbus_bus *bus) +{ +return 0 ; +} + +static inline int security_kdbus_recv (const struct kdbus_conn *conn, +const struct kdbus_bus *bus) +{ +return 0 ; +} + +static inline int security_kdbus_name_acquire (const struct kdbus_conn *conn, +const char *name) +{ +return 0 ; +} + +static inline int security_kdbus_name_list (const struct kdbus_bus *bus) +{ +return 0 ; +} + +static inline int security_kdbus_ep_create (const struct kdbus_bus *bus) +{ +return 0 ; +} + +static inline int security_kdbus_ep_setpolicy (const struct kdbus_bus *bus) +{ +return 0 ; +} + +static inline int security_kdbus_connect (struct kdbus_conn *conn, +const char *secctx,u32 seclen) +{ +return 0 ; +} + +static inline void security_kdbus_conn_free (struct kdbus_conn *conn) +{ +} + +static inline int security_kdbus_conn_info (const struct kdbus_conn *conn) +{ +return 0 ; +} + +static inline int security_kdbus_talk (const struct kdbus_conn *src, +const struct kdbus_conn *dst) +{ +return 0 ; +} +#endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK
security/capability.c +84 -0
96 lines not on this page · raw message
security/security.c +84 -0
90 lines not on this page · raw message
Signature · 1 line
2.1.1
PATCH 5/5 kdbus: make use of new lsm hooks
In reply to a message not in the archiveDANGEROUS: This version has been compile-tested only!
--- drivers/misc/kdbus/bus.c | 10 +++++++++- drivers/misc/kdbus/connection.c | 34 +++++++++++++++++++++++++++++++++- drivers/misc/kdbus/domain.c | 7 +++++++ drivers/misc/kdbus/endpoint.c | 11 +++++++++++ drivers/misc/kdbus/names.c | 9 +++++++++ 5 files changed, 69 insertions(+), 2 deletions(-)
drivers/misc/kdbus/bus.c +9 -1
@@ -18,6 +18,7 @@#include <linux/module.h> #include <linux/random.h> #include <linux/sched.h> +#include <linux/security.h> #include <linux/sizes.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -97,6 +98,7 @@ static void __kdbus_bus_free(struct kref *kref)kdbus_domain_unref (bus->domain);kdbus_policy_db_clear (&bus->policy_db);kdbus_meta_free (bus->meta); +security_kdbus_bus_free (bus);kfree (bus->name);kfree (bus); }
@@ -351,9 +353,13 @@ int kdbus_bus_new(struct kdbus_domain *domain,if (ret <0 ) goto exit_free_name; + ret =security_kdbus_bus_alloc (b); +if (ret) + goto exit_free_reg; + ret =kdbus_ep_new (b,"bus" , mode, uid, gid, false, &b->ep);if (ret <0 ) - goto exit_free_reg; + goto exit_free_security;/* link into domain */ mutex_lock (&domain->lock);
@@ -386,6 +392,8 @@ exit_unref_user_unlock:kdbus_domain_user_unref (b->user);kdbus_ep_disconnect (b->ep);kdbus_ep_unref (b->ep); +exit_free_security: +security_kdbus_bus_free (b); exit_free_reg:kdbus_name_registry_free (b->name_registry); exit_free_name:
drivers/misc/kdbus/connection.c +33 -1
@@ -27,6 +27,7 @@#include <linux/sched.h> #include <linux/shmem_fs.h> #include <linux/sizes.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/syscalls.h>
@@ -282,6 +283,10 @@ int kdbus_cmd_msg_recv(struct kdbus_conn *conn,if (recv->offset >0 )return -EINVAL ; + ret =security_kdbus_recv (conn, conn->ep->bus); +if (ret) +return ret; +mutex_lock (&conn->lock); ret = kdbus_queue_entry_peek(&conn->queue, recv->priority, recv->flags & KDBUS_RECV_USE_PRIORITY,
@@ -460,7 +465,12 @@ static int kdbus_conn_check_access(struct kdbus_ep *ep,if (allowed)return 0 ; -/* ... otherwise, ask the policy DBs for permission */ +/* ... consult LSM */ + ret =security_kdbus_talk (conn_src, conn_dst); +if (ret) +return ret; + +/* ... finally, ask the policy DBs for permission */ ret =kdbus_ep_policy_check_talk_access (ep, conn_src, conn_dst);if (ret <0 )return ret;
@@ -596,6 +606,10 @@ static void kdbus_conn_broadcast(struct kdbus_ep *ep,* data, even when they did not ask for it. */ if (conn_src) { + ret =security_kdbus_talk (conn_src, conn_dst); +if (ret) +continue ; +/* Check if conn_src is allowed to signal */ ret = kdbus_ep_policy_check_broadcast(conn_dst->ep, conn_src,
@@ -736,6 +750,10 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep,bool sync = msg->flags &KDBUS_MSG_FLAGS_SYNC_REPLY ;int ret =0 ; + ret =security_kdbus_send (conn_src, bus); +if (ret) +return ret; +/* assign domain-global message sequence number */ BUG_ON (kmsg->seq >0 ); kmsg->seq =atomic64_inc_return (&bus->domain->msg_seq_last);
@@ -1086,6 +1104,7 @@ static void __kdbus_conn_free(struct kref *kref)kdbus_ep_unref (conn->ep);kdbus_bus_unref (conn->bus);put_cred (conn->cred); +security_kdbus_conn_free (conn);kfree (conn->name);kfree (conn); }
@@ -1467,8 +1486,12 @@ int kdbus_conn_new(struct kdbus_ep *ep,bool is_policy_holder;bool is_activator;bool is_monitor; +u32 len; +u32 sid; +char *label;int ret; +BUG_ON (*c); is_monitor = hello->flags &KDBUS_HELLO_MONITOR ;
@@ -1542,6 +1565,9 @@ int kdbus_conn_new(struct kdbus_ep *ep,return -ENOMEM ;if (is_activator || is_policy_holder) { + ret =security_kdbus_ep_setpolicy (bus); +if (ret) + goto exit_free_conn;/* * Policy holders may install one name, and are * allowed to use wildcards.
@@ -1680,6 +1706,12 @@ int kdbus_conn_new(struct kdbus_ep *ep, goto exit_unref_user_unlock; } +security_task_getsecid (current, &sid); +security_secid_to_secctx (sid, &label, &len); + ret =security_kdbus_connect (conn, label, len); +if (ret <0 ) + goto exit_unref_user_unlock; +/* link into bus and endpoint */ list_add_tail (&conn->ep_entry, &ep->conn_list);hash_add (bus->conn_hash, &conn->hentry, conn->id);
drivers/misc/kdbus/domain.c +7 -0
@@ -18,6 +18,7 @@#include <linux/module.h> #include <linux/sched.h> #include <linux/sizes.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -156,6 +157,7 @@ static void __kdbus_domain_free(struct device *dev)idr_destroy (&domain->user_idr);kfree (domain->name);kfree (domain->devpath); +security_kdbus_domain_free (domain);kfree (domain); }
@@ -255,6 +257,10 @@ int kdbus_domain_new(struct kdbus_domain *parent, const char *name,if (ret <0 ) goto exit_put; + ret =security_kdbus_domain_alloc (d); +if (ret) + goto exit_put; +if (parent) {/* lock order: parent domain -> domain */ mutex_lock (&parent->lock);
@@ -444,6 +450,7 @@ static void __kdbus_domain_user_free(struct kref *kref)hash_del (&user->hentry);mutex_unlock (&user->domain->lock); +security_kdbus_domain_free (user->domain);kdbus_domain_unref (user->domain);kfree (user); }
drivers/misc/kdbus/endpoint.c +11 -0
@@ -17,6 +17,7 @@#include <linux/init.h> #include <linux/module.h> #include <linux/sched.h> +#include <linux/security.h> #include <linux/sizes.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -197,6 +198,10 @@ int kdbus_ep_new(struct kdbus_bus *bus, const char *name,if (ret <0 ) goto exit_put; + ret =security_kdbus_ep_create (bus); +if (ret) + goto exit_put; +mutex_lock (&bus->lock);if (bus->disconnected) {
@@ -255,6 +260,12 @@ int kdbus_ep_policy_set(struct kdbus_ep *ep,const struct kdbus_item *items, size_t items_size) { + int ret; + + ret =security_kdbus_ep_setpolicy (ep->bus); +if (ret) +return ret; +return kdbus_policy_set (&ep->policy_db, items, items_size,0 , true, ep); }
drivers/misc/kdbus/names.c +9 -0
@@ -22,6 +22,7 @@#include <linux/mutex.h> #include <linux/rwsem.h> #include <linux/sched.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -492,6 +493,10 @@ int kdbus_name_acquire(struct kdbus_name_registry *reg,u32 hash;int ret =0 ; + ret =security_kdbus_name_acquire (conn, name); +if (ret) +return ret; +/* lock order: domain -> bus -> ep -> names -> conn */ mutex_lock (&conn->bus->lock);down_write (®->rwlock);
@@ -876,6 +881,10 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg,size_t pos;int ret; + ret =security_kdbus_name_list (conn->bus); +if (ret) +return ret; + policy_db = &conn->ep->policy_db;/* lock order: domain -> bus -> ep -> names -> conn */
Signature · 1 line
2.1.1
Greg KH
maintainerRe: [RFC PATCH 0/5] kdbus: add support for lsm
In reply to Karol LewandowskiQuoted 28 lines · Karol Lewandowski
This is set of EXPERIMENTAL patches adding lsm support to kdbus. (Rebased on top of v3.17.)
Quoted 1 line
From least to most invasive:
- (1) kdbus: extend structures with security pointer for lsm
Trivial. Applicable as-is.
- (2) security: export
security_file_receivefor modules
(3) kdbus: check if lsm permits installing received fds
fd_installdoesn't seem to consult LSM, these patches ensure that receiving process has the right to sent fds.Compile-tested only.
- (4) security: introduce lsm hooks for kdbus
(5) kdbus: make use of new lsm hooksSet of proof-of-concept hooks discussed previously with Paul Moore.
kdbus integration patch (5) for review, but unlikely for integration at this stage.
Likewise, compile-tested only.
Quoted 6 lines
Karol Lewandowski (5):
kdbus: extend structures with security pointer for lsm
security: exportsecurity_file_receivefor modules
kdbus: check if lsm permits installing received fds
security: introduce lsm hooks for kdbus
kdbus: make use of new lsm hooks
These looks reasonable to me, thanks for sending them. They will need to be refreshed again after this next round of changes, but it shouldn't be that hard to do so.
thanks,
greg k-h
Re: [RFC PATCH 0/5] kdbus: add support for lsm
Quoted 36 lines · Greg KH
Quoted 28 lines · Karol Lewandowski
This is set of EXPERIMENTAL patches adding lsm support to kdbus. (Rebased on top of v3.17.)
Quoted 1 line
From least to most invasive:
- (1) kdbus: extend structures with security pointer for lsm
Trivial. Applicable as-is.
- (2) security: export
security_file_receivefor modules
(3) kdbus: check if lsm permits installing received fds
fd_installdoesn't seem to consult LSM, these patches ensure that receiving process has the right to sent fds.Compile-tested only.
- (4) security: introduce lsm hooks for kdbus
(5) kdbus: make use of new lsm hooksSet of proof-of-concept hooks discussed previously with Paul Moore.
kdbus integration patch (5) for review, but unlikely for integration at this stage.
Likewise, compile-tested only.
Quoted 6 lines
Karol Lewandowski (5):
kdbus: extend structures with security pointer for lsm
security: exportsecurity_file_receivefor modules
kdbus: check if lsm permits installing received fds
security: introduce lsm hooks for kdbus
kdbus: make use of new lsm hooks
Quoted 3 lines
These looks reasonable to me, thanks for sending them. They will need to be refreshed again after this next round of changes, but it shouldn't be that hard to do so.
Sure thing.
For completness - there are accompanying Smack and SELinux patches that could go together with above patches, ie.
https://github.com/lmctl/linux/commit/103c26fd27d1ec8c32d85dd3d85681f936ac66fb
http://git.infradead.org/users/pcmoore/selinux/commitdiff/eef4844f91fef6092b6bfac941ebe7f18375be9d
I've got some free time on my hands now, so I'll try to revisit these too.
Cheers,
Karol Lewandowski
Greg Kroah-Hartman
maintainerQuoted 6 lines · Jiri Kosina
Quoted 3 lines · Greg Kroah-Hartman
kdbus is a kernel-level IPC implementation that aims for resemblance to the the protocol layer with the existing userspace D-Bus daemon while enabling some features that couldn't be implemented before in userspace.
Quoted 8 lines
I'd be interested in the features that can't be implemented in userspace (and therefore would justify existence of kdbus in the kernel). Could you please point me to such list / documentation?
It seems to me that most of the highlight features from the cover letter can be "easily" (for certain definition of that word, of course) implemented in userspace (
vmsplice(), sending fd through unix socket, user namespaces, UUID management, etc).
Sorry for the long delay in getting back to this, I'm battling a bad case of jet-lag at the moment...
Here's some reasons why I feel it is better to have kdbus in the kernel rather than trying to implement the same thing in a userspace daemon:
- performance: fewer process context switches, fewer copies, fewer syscalls, larger memory chunks via memfd. This is really important for a whole class of userspace programs that are ported from other operating systems that are run on tiny ARM systems that rely on hundreds of thousands of messages passed at boot time, and at "critical" times in their user interaction loops.
- security: the peers which communicate do not have to trust each other, as the only trustworthy compoenent in the game is the kernel which adds metadata and ensures that all data passed as payload is either copied or sealed, so that the receiver can parse the data without having to protect against changing memory while parsing buffers. Also, all the data transfer is controlled by the kernel, so that LSMs can track and control what is going on, without involving userspace. Because of the LSM issue, security people are much happier with this model than the current scheme of having to hook into dbus to mediate things.
- more metadata can be attached to messages than in userspace
- semantics for apps with heavy data payloads (media apps, for instance) with optinal priority message dequeuing, and global message ordering. Some "crazy" people are playing with using kdbus for audio data in the system. I'm not saying that this is the best model for this, but until now, there wasn't any other way to do this without having to create custom "busses", one for each application library.
- being in the kernle closes a lot of races which can't be fixed with the current userspace solutions. For example, with kdbus, there is a way a client can disconnect from a bus, but do so only if no further messages present in its queue, which is crucial for implementing race-free "exit-on-idle" services
- eavesdropping on the kernel level, so privileged users can hook into the message stream without hacking support for that into their userspace processes
- a number of smaller benefits: for example kdbus learned a way to peek full messages without dequeing them, which is really useful for logging metadata when handling bus-activation requests.
Of course, some of the bits above could be implemented in userspace alone, for example with more sophisticated memory management APIs, but this is usually done by losing out on the other details. For example, for many of the memory management APIs, it's hard to not require the communicating peers to fully trust each other. And we _really_ don't want peers to have to trust each other.
Another benefit of having this in the kernel, rather than as a userspace daemon, is that you can now easily use the bus from the initrd, or up to the very end when the system shuts down. On current userspace D-Bus, this is not really possible, as this requires passing the bus instance around between initrd and the "real" system. Such a transition of all fds also requires keeping full state of what has already been read from the connection fds. kdbus makes this much simpler, as we can change the ownership of the bus, just by passing one fd over from one part to the other.
Regarding binder: binder and kdbus follow very different design concepts. Binder implies the use of thread-pools to dispatch incoming method calls. This is a very efficient scheme, and completely natural in programming languages like Java. On most Linux programs, however, there's a much stronger focus on central poll() loops that dispatch all sources a program cares about. kdbus is much more usable in such environments, as it doesn't enforce a threading model, and it is happy with serialized dispatching. In fact, this major difference had an effect on much of the design decisions: binder does not guarantee global message ordering due to the parallel dispatching in the thread-pools, but kdbus does. Moreover, there's also a difference in the way message handling. In kdbus, every message is basically taken and dispatched as one blob, while in binder, continious connections to other peers are created, which are then used to send messages on. Hence, the models are quite different, and they serve different needs. I believe that the D-Bus/kdbus model is more compatible and friendly with how Linux programs are usually implemented. I went into the kdbus vs. binder stuff in a blog post that I linked to earlier in this thread that goes into more detail here.
Hopefully this helps explain why I feel kdbus should be in the kernel and not a userspace daemon. I'll put this information in the cover letter for the next round of patches that are sent out.
thanks,
greg k-h
Quoted 2 lines · On Sat, 1 Nov 2014 18:21:30 -0700 Greg Kroah-Hartman…
Here's some reasons why I feel it is better to have kdbus in the kernel rather than trying to implement the same thing in a userspace daemon:
No - these are reasons to have *something* in the kernel. I think it would be far more constructive to treat the current kdbus as a proof of concept/prototype or even a draft requirements specification.
Quoted 3 lines
as the only trustworthy compoenent in the game is the kernel which adds metadata and ensures that all data passed as payload is either copied or sealed, so that the receiver can parse the data without
When the kernel adds metadata without being told to do so by one end of the link you create a new set of security and privacy leaks. Far better that the sender must choose what metadata is added and the receiver can decide to bin stuff that's not acceptable. The job of the kernel is really more like that of an auditor in a business transaction - to make sure that the data they agree to pass is truthful.
(ie its the sender who must say "attach my user info", the receiver who must say "no info, no play" and the kernel who must provide the info so it can't be faked.
Quoted 2 lines
- semantics for apps with heavy data payloads (media apps, for instance) with optinal priority message dequeuing, and global message ordering.
Sounds like System 5 IPC ;-)
Quoted 2 lines
Regarding binder: binder and kdbus follow very different design concepts.
We know binder is broken but the Android guys are stuck in a special kind of hell with it for some years to come. We need to make sure kdbus isn't the same result.
Alan
Arnd Bergmann
maintainerQuoted 10 lines · On Wednesday 29 October 2014 15:00:44 Greg Kroah-Hartman wrote:
drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/kdbus/Kconfig | 11 + drivers/misc/kdbus/Makefile | 19 + drivers/misc/kdbus/bus.c | 450 ++++++ drivers/misc/kdbus/bus.h | 107 ++ drivers/misc/kdbus/connection.c | 1751 +++++++++++++++++++++ drivers/misc/kdbus/connection.h | 177 +++ drivers/misc/kdbus/domain.c | 477 ++++++
One very high-level common:
Since this is going to be a very commonly used IPC mechanism, I don't like the idea of stuffing it into drivers/misc.
How about putting it into drivers/kdbus or ipc/kdbus instead?
Arnd
Greg Kroah-Hartman
maintainerQuoted 12 lines · Arnd Bergmann
Quoted 10 lines · On Wednesday 29 October 2014 15:00:44 Greg Kroah-Hartman wrote:
drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/kdbus/Kconfig | 11 + drivers/misc/kdbus/Makefile | 19 + drivers/misc/kdbus/bus.c | 450 ++++++ drivers/misc/kdbus/bus.h | 107 ++ drivers/misc/kdbus/connection.c | 1751 +++++++++++++++++++++ drivers/misc/kdbus/connection.h | 177 +++ drivers/misc/kdbus/domain.c | 477 ++++++
Quoted 6 lines
One very high-level common:
Since this is going to be a very commonly used IPC mechanism, I don't like the idea of stuffing it into
drivers/misc.How about putting it into
drivers/kdbusor ipc/kdbus instead?
ipc/kdbus seems good to me. I didn't want to "pollute" drivers/ with any new subdirectories, it seems to grow fast enough as it is...
greg k-h