binder: restrict BINDER_NLGRP_REPORT to CAP_NET_ADMIN and fix binderfs minor leak
PATCH 1/1 binder: restrict BINDER_NLGRP_REPORT to CAP_NET_ADMIN and fix binderfs minor leak
Fix three security and resource-accounting issues in binder_netlink.c and binderfs.c:
1. In drivers/android/binder_netlink.c, binder_nl_mcgrps[BINDER_NLGRP_REPORT] is declared without .flags = GENL_MCAST_CAP_NET_ADMIN, allowing any unprivileged local user to subscribe to the BINDER_NLGRP_REPORT Generic Netlink multicast group and monitor system-wide binder transaction error reports (including sender/target PIDs and transaction metadata).
2. In drivers/android/binderfs.c, binderfs_binder_ctl_create() allocates an IDA minor via ida_alloc_max(&binderfs_minors, ...), and if d_alloc_name(root, "binder-control") fails, jumps to out: (which calls kfree(device)) without freeing minor from binderfs_minors.
3. When the binder-control inode (device->context.name == NULL) is evicted in binderfs_evict_inode(), --info->device_count is decremented even though binderfs_binder_ctl_create() never incremented info->device_count, underflowing info->device_count. Only decrement info->device_count when device->context.name is non-NULL.
--- drivers/android/binder_netlink.c | 2 +- drivers/android/binderfs.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/android/binder_netlink.c +1 -1
@@ -16,7 +16,7 @@ static const struct genl_split_ops binder_nl_ops[] = { };static const struct genl_multicast_group binder_nl_mcgrps[] = { - [BINDER_NLGRP_REPORT ] = {"report" , }, + [BINDER_NLGRP_REPORT ] = {"report" , .flags =GENL_MCAST_CAP_NET_ADMIN }, };struct genl_family binder_nl_family__ro_after_init = {
drivers/android/binderfs.c +7 -2
@@ -258,7 +258,8 @@ static void binderfs_evict_inode(struct inode *inode)return ;mutex_lock (&binderfs_minors_mutex); - --info->device_count; +if (device->context.name) + --info->device_count;ida_free (&binderfs_minors, device->miscdev.minor);mutex_unlock (&binderfs_minors_mutex);
@@ -430,8 +431,12 @@ static int binderfs_binder_ctl_create(struct super_block *sb) device->miscdev.minor = minor; dentry =d_alloc_name (root,"binder-control" ); -if (!dentry) +if (!dentry) { +mutex_lock (&binderfs_minors_mutex); +ida_free (&binderfs_minors, minor); +mutex_unlock (&binderfs_minors_mutex); goto out; + } inode->i_private = device; info->control_dentry = dentry;
Greg KH
maintainerQuoted 12 lines · Hui Peng
Fix three security and resource-accounting issues in
binder_netlink.candbinderfs.c:1. In
drivers/android/binder_netlink.c,binder_nl_mcgrps[BINDER_NLGRP_REPORT]is declared without.flags = GENL_MCAST_CAP_NET_ADMIN, allowing any unprivileged local user to subscribe to theBINDER_NLGRP_REPORTGeneric Netlink multicast group and monitor system-wide binder transaction error reports (including sender/target PIDs and transaction metadata).
2. Indrivers/android/binderfs.c,binderfs_binder_ctl_create()allocates an IDA minor viaida_alloc_max(&binderfs_minors, ...), and ifd_alloc_name(root, "binder-control")fails, jumps toout:
Quoted 8 lines
(which calls
kfree(device)) without freeingminorfrombinderfs_minors.
3. When thebinder-controlinode (device->context.name == NULL) is evicted inbinderfs_evict_inode(),--info->device_countis decremented even thoughbinderfs_binder_ctl_create()never incrementedinfo->device_count, underflowinginfo->device_count. Only decrementinfo->device_countwhendevice->context.nameis non-NULL.
Why isn't this 3 different patches?
thanks,
greg kh
Carlos Llamas
maintainerQuoted 9 lines · Hui Peng
Fix three security and resource-accounting issues in
binder_netlink.candbinderfs.c:1. In
drivers/android/binder_netlink.c,binder_nl_mcgrps[BINDER_NLGRP_REPORT]is declared without.flags = GENL_MCAST_CAP_NET_ADMIN, allowing any unprivileged local user to subscribe to theBINDER_NLGRP_REPORTGeneric Netlink multicast group and monitor system-wide binder transaction error reports (including sender/target PIDs and transaction metadata).
Yeap, the whole point is for selinux approved processes to subscribe to these reports.
Quoted 5 lines
2. In
drivers/android/binderfs.c,binderfs_binder_ctl_create()allocates an IDA minor viaida_alloc_max(&binderfs_minors, ...), and ifd_alloc_name(root, "binder-control")fails, jumps toout:(which callskfree(device)) without freeingminorfrombinderfs_minors.
This is already fixed by:
https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
3. When the
binder-controlinode (device->context.name == NULL) is evicted inbinderfs_evict_inode(),--info->device_countis decremented even thoughbinderfs_binder_ctl_create()never incrementedinfo->device_count, underflowinginfo->device_count. Only decrementinfo->device_countwhendevice->context.nameis non-NULL.
I haven't looked closely at this one but it sounds like a real issue. However, it would still need to be a separate patch, so please drop the rest and please use the appropriate Fixes: tag.
Note this code has now been removed, but we may need to take the fix for stable and downstream Android branches.
Thanks,
Carlos Llamas