From 5fee496e6220228b4a9059e06e430178ee1ba1ec Mon Sep 17 00:00:00 2001 From: Sandeep Patil Date: Wed, 7 Dec 2016 10:55:45 -0800 Subject: [PATCH] socket: uevent: use SO_RCVBUF instead of SO_RCVBUFFORCE The SO_RCVBUFFORCE option requires the caller of uevent_create_socket() to have net_admin capabilities. Set platform default rcv/snd buffer sizes to 256kb that will always be overridden by the device/target. However, it will allow ueventd / healthd to use the uevent_create_socket() API w/o requiring the net_admin capability. Note: All devices override the buffer sizes according to the technology maximum to at least ~8MB. So, the init.rc change here is to make sure platform code can work w/o any overrides. Test: no SELinux failures for healthd with 'net_admin' removed. Bug: https://b/32733887 Change-Id: Ida346468cd550ad07901bf3a78ad508939849906 Signed-off-by: Sandeep Patil --- libcutils/uevent.c | 7 ++++++- rootdir/init.rc | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libcutils/uevent.c b/libcutils/uevent.c index de5d227be..f548dca2f 100644 --- a/libcutils/uevent.c +++ b/libcutils/uevent.c @@ -116,7 +116,12 @@ int uevent_open_socket(int buf_sz, bool passcred) if(s < 0) return -1; - setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &buf_sz, sizeof(buf_sz)); + /* buf_sz should be less than net.core.rmem_max for this to succeed */ + if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &buf_sz, sizeof(buf_sz)) < 0) { + close(s); + return -1; + } + setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { diff --git a/rootdir/init.rc b/rootdir/init.rc index 8903255d4..249b9e285 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -125,6 +125,12 @@ on init write /proc/sys/kernel/sched_rt_runtime_us 950000 write /proc/sys/kernel/sched_rt_period_us 1000000 + # Assign reasonable ceiling values for socket rcv/snd buffers. + # These should almost always be overridden by the target per the + # the corresponding technology maximums. + write /proc/sys/net/core/rmem_max 262144 + write /proc/sys/net/core/wmem_max 262144 + # reflect fwmark from incoming packets onto generated replies write /proc/sys/net/ipv4/fwmark_reflect 1 write /proc/sys/net/ipv6/fwmark_reflect 1