From nobody Tue Nov 26 04:24:55 2024 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB1331F942E for ; Mon, 21 Oct 2024 18:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729535315; cv=none; b=oLf2Tv4RsF3J+CVK1IPeqLYCEeCOyItPFiGDa3ET3pXIOJVx9/ZlHSQfcYR2KfvMFiOd6bE/zMaJeD/Hc6BhniGnsvvagRkK+ylM/YxYd5jbGUwCCRia0rdCAj9G1ohC1/GTr4JH+19vFqQxaAztXl0sw7jlBXJGCugGWAdGxMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729535315; c=relaxed/simple; bh=9phmniRB+p2YydWbCMYDY+gb0TGXKGXiJYSX9CmTGpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LKr5x+6mU85hVlQfAWyuDTGATt+PQmGJBZ0bIabr2WEVTyIbq96n9IaxG/57Fed1+JKhgRRWoo88OABrfJH1JQb5tljJfKTPkvntcAFe5OVIKygegojq6UJLPFHbviicQ5e1KeX4/p5yNPOhL04aEC9/JN3iXer4CElyAPOCXsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=LXfUmyr0; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="LXfUmyr0" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-20cb89a4e4cso32986885ad.3 for ; Mon, 21 Oct 2024 11:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729535312; x=1730140112; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lSyI3CyUaFFHrGu+rJ3IzJTwLh2a5uYdcOGIQaWuWS4=; b=LXfUmyr0bc773X8qGvFN4Nk/+u1TdZZPWQmkTCnRurKINVx6PXyMV+dqD9Gsj+X5Xe n20URlqKoiwrSs/A3RMq8f1/jcDE99iLeSmS2oxP5oYEbI7DHCae/0aA7v8y72aHR5XZ WXnMXvevp5TmLQm+anQYxNShmhIu1WaXn3GKU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729535312; x=1730140112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lSyI3CyUaFFHrGu+rJ3IzJTwLh2a5uYdcOGIQaWuWS4=; b=pyM9BzvzHTiBKk+7tBTLjgDJVCtdUc6DSormowwUZ3lx1hxuip15I9bTNWzxpukUR+ zvU/Xh8ggXeaJDyGoqoq5hybJ7zbaS12QKYAwEEA6MfyCjfAXluGjaU/dPNFFos/JLaw DdNgslqjBi9zRwyUnyxNvD9wusPaRTv0EQK2nPkzmYi3Jd0NxDbn7QJ/8sjQf90rYV/F M+K+t3dJyMu/LtODEqKhOBjPIIcABVrIg7RGd8V+Sh7/5iWN2hKHyrbUxhWO4l0kI3Ou f2Ynvi8RMP/IkQwZNxGd4/d4owAKCcDH60XXmv+nAVBHww8UWrFroawMoe93vrSxaVF3 wRYg== X-Forwarded-Encrypted: i=1; AJvYcCVFYQlIO+VlsxfXoDJdAjWdIbPq37FXdFQyMNJpf8RgtbvQyqAO1Kt8ExEqAiZ81T6LcfqFafGUCALGZYM=@vger.kernel.org X-Gm-Message-State: AOJu0YzSOLzKlPZxam0CJzDf4FOEbj3c3XbNcp8LvDOmuDuOVbfVrLBg GcRdAshoC5RybLB4wjiR7aNPnXGbOn+1btHaY1bT49yhI35Ckvp3GiV6Qkch5w== X-Google-Smtp-Source: AGHT+IFxQz1H0UseuXuzzeZtw9wA7Tw0sqwLOlCbZRcJDXCVQegZM8dPZxHPZBqWGuAzf6f+jSHs5g== X-Received: by 2002:a17:902:ce88:b0:20c:a97d:cc7f with SMTP id d9443c01a7336-20e5a8fb24dmr219693765ad.41.1729535311790; Mon, 21 Oct 2024 11:28:31 -0700 (PDT) Received: from li-cloudtop.c.googlers.com.com (43.222.125.34.bc.googleusercontent.com. [34.125.222.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0f3c95sm28914195ad.253.2024.10.21.11.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 11:28:31 -0700 (PDT) From: Li Li To: dualli@google.com, corbet@lwn.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, donald.hunter@gmail.com, gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, brauner@kernel.org, cmllamas@google.com, surenb@google.com, arnd@arndb.de, masahiroy@kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, netdev@vger.kernel.org, hridya@google.com, smoreland@google.com Cc: kernel-team@android.com Subject: [PATCH v3 1/1] binder: report txn errors via generic netlink Date: Mon, 21 Oct 2024 11:28:20 -0700 Message-ID: <20241021182821.1259487-2-dualli@chromium.org> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog In-Reply-To: <20241021182821.1259487-1-dualli@chromium.org> References: <20241021182821.1259487-1-dualli@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li Li Frozen tasks can't process binder transactions, so sync binder transactions will fail with BR_FROZEN_REPLY and async binder transactions will be queued in the kernel async binder buffer. As these queued async transactions accumulates over time, the async buffer will eventually be running out, denying all new transactions after that with BR_FAILED_REPLY. In addition to the above cases, different kinds of binder error codes might be returned to the sender. However, the core Linux, or Android, system administration process never knows what's actually happening. This patch introduces the Linux generic netlink messages into the binder driver so that the Linux/Android system administration process can listen to important events and take corresponding actions, like stopping a broken app from attacking the OS by sending huge amount of spamming binder transactions. To prevent making the already bloated binder.c even bigger, a new source file binder_genl.c is created to host those generic netlink code. Signed-off-by: Li Li --- Documentation/admin-guide/binder_genl.rst | 71 ++++++ Documentation/admin-guide/index.rst | 1 + drivers/android/Kconfig | 1 + drivers/android/Makefile | 2 +- drivers/android/binder.c | 82 ++++++- drivers/android/binder_genl.c | 249 ++++++++++++++++++++++ drivers/android/binder_internal.h | 31 +++ drivers/android/binder_trace.h | 37 ++++ drivers/android/binderfs.c | 4 + include/uapi/linux/android/binder.h | 132 ++++++++++++ 10 files changed, 606 insertions(+), 4 deletions(-) create mode 100644 Documentation/admin-guide/binder_genl.rst create mode 100644 drivers/android/binder_genl.c diff --git a/Documentation/admin-guide/binder_genl.rst b/Documentation/admi= n-guide/binder_genl.rst new file mode 100644 index 000000000000..923a67bbf8ec --- /dev/null +++ b/Documentation/admin-guide/binder_genl.rst @@ -0,0 +1,71 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Generic Netlink for the Android Binder Driver (Binder Genl) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The Generic Netlink subsystem in the Linux kernel provides a generic way f= or +the Linux kernel to communicate to the user space applications. In the ker= nel +binder driver, it is used to report various kinds of binder transactions to +user space administratioin process. The binder driver allows multiple bind= er +devices and their correspondign binder contexts. Each binder context has a +independent Generic Netlink for security reason. To prevent untrusted user +applications from accessing the netlink data, the kernel driver uses unica= st +mode instead of multicast. + +Using Binder Genl +----------------- + +The Binder Genl can be used in the same way as any other generic netlink +drivers. The user space application uses a raw netlink socket to send comm= ands +to and receive packets from the kernel driver. + +NOTE: if the user applications that talks to the Binder Genl driver exits, +the kernel driver will automatically reset the configuration to the default +and stop sending more reports to prevent leaking memory. + +Usage example (user space pseudo code): + +:: + + // open netlink socket + int fd =3D socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + + // bind netlink socket + bind(fd, struct socketaddr); + + // get the family id of the binder genl + send(fd, CTRL_CMD_GETFAMILY, CTRL_ATTR_FAMILY_NAME, "binder"); + void *data =3D recv(CTRL_CMD_NEWFAMILY); + __u16 id =3D nla(data)[CTRL_ATTR_FAMILY_ID]; + + // enable per-context binder report + send(fd, id, BINDER_GENL_SET_REPORT, 0, BINDER_REPORT_ALL); + + // confirm the per-context configuration + void *data =3D recv(fd, BINDER_GENL_CMD_REPLY); + __u32 pid =3D nla(data)[BINDER_GENL_ATTR_PID]; + __u32 flags =3D nla(data)[BINDER_GENL_ATTR_FLAGS]; + + // set optional per-process report, overriding the per-context one + send(fd, id, BINDER_GENL_SET_REPORT, getpid(), + BINDER_REPORT_FAILED | BINDER_REPORT_OVERRIDE); + + // confirm the optional per-process configuration + void *data =3D recv(fd, BINDER_GENL_CMD_REPLY); + __u32 pid =3D nla(data)[BINDER_GENL_ATTR_PID]; + __u32 flags =3D nla(data)[BINDER_GENL_ATTR_FLAGS]; + + // wait and read all binder reports + while (running) { + void *data =3D recv(fd, BINDER_GENL_CMD_REPORT); + struct binder_report report =3D nla(data)[BINDER_GENL_ATTR_REP= ORT]; + + // process struct binder_report + do_something(&report); + } + + // clean up + send(fd, id, BINDER_GENL_SET_REPORT, 0, 0); + send(fd, id, BINDER_GENL_SET_REPORT, getpid(), 0); + close(fd); diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guid= e/index.rst index e85b1adf5908..b3b5cfadffe5 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -79,6 +79,7 @@ configure specific aspects of kernel behavior to your lik= ing. aoe/index auxdisplay/index bcache + binder_genl binderfs binfmt-misc blockdev/index diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig index 07aa8ae0a058..e2fa620934e2 100644 --- a/drivers/android/Kconfig +++ b/drivers/android/Kconfig @@ -4,6 +4,7 @@ menu "Android" config ANDROID_BINDER_IPC bool "Android Binder IPC Driver" depends on MMU + depends on NET default n help Binder is used in Android for both communication between processes, diff --git a/drivers/android/Makefile b/drivers/android/Makefile index c9d3d0c99c25..d818447fbc4c 100644 --- a/drivers/android/Makefile +++ b/drivers/android/Makefile @@ -2,5 +2,5 @@ ccflags-y +=3D -I$(src) # needed for trace events =20 obj-$(CONFIG_ANDROID_BINDERFS) +=3D binderfs.o -obj-$(CONFIG_ANDROID_BINDER_IPC) +=3D binder.o binder_alloc.o +obj-$(CONFIG_ANDROID_BINDER_IPC) +=3D binder.o binder_alloc.o binder_genl.o obj-$(CONFIG_ANDROID_BINDER_IPC_SELFTEST) +=3D binder_alloc_selftest.o diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 978740537a1a..c99d6c6ff13b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3678,10 +3678,25 @@ static void binder_transaction(struct binder_proc *= proc, return_error_line =3D __LINE__; goto err_copy_data_failed; } - if (t->buffer->oneway_spam_suspect) + if (t->buffer->oneway_spam_suspect) { tcomplete->type =3D BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT; - else + if (binder_genl_report_enabled(proc, BINDER_REPORT_SPAM)) { + struct binder_report report; + + report.err =3D BR_ONEWAY_SPAM_SUSPECT; + report.from_pid =3D proc->pid; + report.from_tid =3D thread->pid; + report.to_pid =3D target_proc ? target_proc->pid : 0; + report.to_tid =3D target_thread ? target_thread->pid : 0; + report.reply =3D reply; + report.flags =3D tr->flags; + report.code =3D tr->code; + report.data_size =3D tr->data_size; + binder_genl_send_report(context, &report, sizeof(report)); + } + } else { tcomplete->type =3D BINDER_WORK_TRANSACTION_COMPLETE; + } t->work.type =3D BINDER_WORK_TRANSACTION; =20 if (reply) { @@ -3731,8 +3746,24 @@ static void binder_transaction(struct binder_proc *p= roc, * process and is put in a pending queue, waiting for the target * process to be unfrozen. */ - if (return_error =3D=3D BR_TRANSACTION_PENDING_FROZEN) + if (return_error =3D=3D BR_TRANSACTION_PENDING_FROZEN) { tcomplete->type =3D BINDER_WORK_TRANSACTION_PENDING; + if (binder_genl_report_enabled(proc, BINDER_REPORT_DELAYED)) { + struct binder_report report; + + report.err =3D return_error; + report.from_pid =3D proc->pid; + report.from_tid =3D thread->pid; + report.to_pid =3D target_proc ? target_proc->pid : 0; + report.to_tid =3D target_thread ? target_thread->pid : 0; + report.reply =3D reply; + report.flags =3D tr->flags; + report.code =3D tr->code; + report.data_size =3D tr->data_size; + binder_genl_send_report(context, &report, + sizeof(report)); + } + } binder_enqueue_thread_work(thread, tcomplete); if (return_error && return_error !=3D BR_TRANSACTION_PENDING_FROZEN) @@ -3794,6 +3825,21 @@ static void binder_transaction(struct binder_proc *p= roc, binder_dec_node_tmpref(target_node); } =20 + if (binder_genl_report_enabled(proc, BINDER_REPORT_FAILED)) { + struct binder_report report; + + report.err =3D return_error; + report.from_pid =3D proc->pid; + report.from_tid =3D thread->pid; + report.to_pid =3D target_proc ? target_proc->pid : 0; + report.to_tid =3D target_thread ? target_thread->pid : 0; + report.reply =3D reply; + report.flags =3D tr->flags; + report.code =3D tr->code; + report.data_size =3D tr->data_size; + binder_genl_send_report(context, &report, sizeof(report)); + } + binder_debug(BINDER_DEBUG_FAILED_TRANSACTION, "%d:%d transaction %s to %d:%d failed %d/%d/%d, size %lld-%lld line= %d\n", proc->pid, thread->pid, reply ? "reply" : @@ -6114,6 +6160,11 @@ static int binder_release(struct inode *nodp, struct= file *filp) =20 binder_defer_work(proc, BINDER_DEFERRED_RELEASE); =20 + if (proc->pid =3D=3D proc->context->report_portid) { + proc->context->report_portid =3D 0; + proc->context->report_flags =3D 0; + } + return 0; } =20 @@ -6311,6 +6362,26 @@ binder_defer_work(struct binder_proc *proc, enum bin= der_deferred_state defer) mutex_unlock(&binder_deferred_lock); } =20 +/** + * binder_find_proc() - set binder report flags + * @pid: the target process + */ +struct binder_proc *binder_find_proc(int pid) +{ + struct binder_proc *proc; + + mutex_lock(&binder_procs_lock); + hlist_for_each_entry(proc, &binder_procs, proc_node) { + if (proc->pid =3D=3D pid) { + mutex_unlock(&binder_procs_lock); + return proc; + } + } + mutex_unlock(&binder_procs_lock); + + return NULL; +} + static void print_binder_transaction_ilocked(struct seq_file *m, struct binder_proc *proc, const char *prefix, @@ -6920,6 +6991,11 @@ static int __init init_binder_device(const char *nam= e) =20 hlist_add_head(&binder_device->hlist, &binder_devices); =20 + binder_device->context.report_seq =3D (atomic_t)ATOMIC_INIT(0); + ret =3D binder_genl_init(&binder_device->context.genl_family, name); + if (ret < 0) + kfree(binder_device); + return ret; } =20 diff --git a/drivers/android/binder_genl.c b/drivers/android/binder_genl.c new file mode 100644 index 000000000000..8f82f039bc17 --- /dev/null +++ b/drivers/android/binder_genl.c @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* binder_genl.c + * + * Android IPC Subsystem + * + * Copyright (C) 2024 Google, Inc. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +#include "binder_internal.h" +#include "binder_trace.h" + +/* + * The default multicast group + */ +static const struct genl_multicast_group binder_genl_mcgrps[] =3D { + { .name =3D "binder_genl", }, +}; + +/* + * The policy to verify the type of the binder genl data + */ +static const struct nla_policy binder_report_policy[BINDER_GENL_ATTR_MAX += 1] =3D { + [BINDER_GENL_ATTR_PID] =3D { .type =3D NLA_U32 }, + [BINDER_GENL_ATTR_FLAGS] =3D { .type =3D NLA_U32 }, +}; + +/** + * binder_genl_cmd_doit() - .doit handler for BINDER_GENL_CMD_SET_REPORT + * @skb: the metadata struct passed from netlink driver + * @info: the generic netlink struct passed from netlink driver + * + * Implements the .doit function to process binder genl commands. + */ +static int binder_genl_cmd_doit(struct sk_buff *skb, struct genl_info *inf= o) +{ + int len; + int portid; + u32 pid; + u32 flags; + void *hdr; + struct binder_context *context; + + /* Both attributes are required for BINDER_GENL_CMD_SET_REPORT */ + if (!info->attrs[BINDER_GENL_ATTR_PID] || !info->attrs[BINDER_GENL_ATTR_F= LAGS]) { + pr_err("Attributes not set\n"); + return -EINVAL; + } + + portid =3D nlmsg_hdr(skb)->nlmsg_pid; + pid =3D nla_get_u32(info->attrs[BINDER_GENL_ATTR_PID]); + flags =3D nla_get_u32(info->attrs[BINDER_GENL_ATTR_FLAGS]); + context =3D container_of(info->family, struct binder_context, + genl_family); + + if (context->report_portid && context->report_portid !=3D portid) { + pr_err("No permission to set report flags from %u\n", portid); + return -EPERM; + } + + if (binder_genl_set_report(context, pid, flags) < 0) { + pr_err("Failed to set report flags %u for %u\n", flags, pid); + return -EINVAL; + } + + len =3D nla_total_size(sizeof(pid)) + nla_total_size(sizeof(flags)); + skb =3D genlmsg_new(len, GFP_KERNEL); + if (!skb) { + pr_err("Failed to alloc binder genl reply message\n"); + return -ENOMEM; + } + + hdr =3D genlmsg_put_reply(skb, info, info->family, 0, + BINDER_GENL_CMD_REPLY); + if (!hdr) + goto free_skb; + + if (nla_put_u32(skb, BINDER_GENL_ATTR_PID, pid)) + goto cancel_skb; + + if (nla_put_u32(skb, BINDER_GENL_ATTR_FLAGS, flags)) + goto cancel_skb; + + genlmsg_end(skb, hdr); + + if (genlmsg_reply(skb, info)) { + pr_err("Failed to send binder genl reply message\n"); + return -EFAULT; + } + + if (!context->report_portid) + context->report_portid =3D portid; + + return 0; + +cancel_skb: + pr_err("Failed to add genl header to reply message\n"); + genlmsg_cancel(skb, hdr); + +free_skb: + pr_err("Failed to add genl attribute to reply message\n"); + nlmsg_free(skb); + return -EMSGSIZE; +} + +/* + * binder_genl_ops - the small version of generic netlink operations + */ +static struct genl_small_ops binder_genl_ops[] =3D { + { + .cmd =3D BINDER_GENL_CMD_SET_REPORT, + .doit =3D binder_genl_cmd_doit, + } +}; + +/** + * binder_genl_init() - initialize binder generic netlink + * @family: the generic netlink family + * @name: the binder device name + * + * Registers the binder generic netlink family. + */ +int binder_genl_init(struct genl_family *family, const char *name) +{ + int ret; + + strscpy(family->name, name, GENL_NAMSIZ); + family->version =3D BINDER_GENL_VERSION; + family->maxattr =3D BINDER_GENL_ATTR_MAX; + family->policy =3D binder_report_policy; + family->small_ops =3D binder_genl_ops; + family->n_small_ops =3D ARRAY_SIZE(binder_genl_ops); + family->mcgrps =3D binder_genl_mcgrps; + family->n_mcgrps =3D ARRAY_SIZE(binder_genl_mcgrps); + ret =3D genl_register_family(family); + if (ret) { + pr_err("Failed to register binder genl: %s\n", name); + return ret; + } + + return 0; +} + +/** + * binder_genl_set_report() - set binder report flags + * @proc: the binder_proc calling the ioctl + * @pid: the target process + * @flags: the flags to set + * + * If pid is 0, the flags are applied to the whole binder context. + * Otherwise, the flags are applied to the specific process only. + */ +int binder_genl_set_report(struct binder_context *context, u32 pid, u32 fl= ags) +{ + struct binder_proc *proc; + + if (flags !=3D (flags & (BINDER_REPORT_ALL | BINDER_REPORT_OVERRIDE))) { + pr_err("Invalid binder report flags: %u\n", flags); + return -EINVAL; + } + + if (!pid) { + /* Set the global flags for the whole binder context */ + context->report_flags =3D flags; + } else { + /* Set the per-process flags */ + proc =3D binder_find_proc(pid); + if (!proc) { + pr_err("Invalid binder report pid %u\n", pid); + return -EINVAL; + } + + proc->report_flags =3D flags; + } + + return 0; +} + +/** + * binder_genl_report_enabled() - check if binder genl reports are enabled + * @proc: the binder_proc to check + * @mask: the categories of binder genl reports + * + * Returns true if certain binder genl reports are enabled for this binder + * proc (when per-process overriding takes effect) or context. + */ +inline bool binder_genl_report_enabled(struct binder_proc *proc, u32 mask) +{ + struct binder_context *context =3D proc->context; + + if (!context->report_portid) + return false; + + if (proc->report_flags & BINDER_REPORT_OVERRIDE) + return (proc->report_flags & mask) !=3D 0; + else + return (context->report_flags & mask) !=3D 0; +} + +/** + * binder_genl_send_report() - send one binder genl report + * @context: the binder context + * @report: the binder genl report to send + * @len: the length of the report data + * + * Packs the report data into a BINDER_GENL_ATTR_REPORT packet and send it. + */ +void binder_genl_send_report(struct binder_context *context, + struct binder_report *report, int len) +{ + int ret; + struct sk_buff *skb; + void *hdr; + + trace_binder_send_report(context->name, report, len); + + skb =3D genlmsg_new(nla_total_size(len), GFP_KERNEL); + if (!skb) { + pr_err("Failed to alloc binder genl message\n"); + return; + } + + hdr =3D genlmsg_put(skb, 0, atomic_inc_return(&context->report_seq), + &context->genl_family, 0, BINDER_GENL_CMD_REPORT); + if (!hdr) { + pr_err("Failed to set binder genl header\n"); + kfree_skb(skb); + return; + } + + if (nla_put(skb, BINDER_GENL_ATTR_REPORT, len, report)) { + genlmsg_cancel(skb, hdr); + nlmsg_free(skb); + return; + } + + genlmsg_end(skb, hdr); + + ret =3D genlmsg_unicast(&init_net, skb, context->report_portid); + if (ret < 0) + pr_err("Failed to send binder genl message to %d: %d\n", + context->report_portid, ret); +} diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_int= ernal.h index f8d6be682f23..7264d8bedf90 100644 --- a/drivers/android/binder_internal.h +++ b/drivers/android/binder_internal.h @@ -12,15 +12,32 @@ #include #include #include +#include #include #include "binder_alloc.h" #include "dbitmap.h" =20 +/** + * struct binder_context - information about a binder domain + * @binder_context_mgr_node: the context manager + * @context_mgr_node_lock: the lock protecting the above context manager= node + * @binder_context_mgr_uid: the uid of the above context manager + * @name: the name of the binder device + * @genl_family: the generic netlink family + * @report_portid: the netlink socket to receive binder reports + * @report_flags: the categories of binder transactions that wo= uld + * be reported (see enum binder_report_flag). + * @report_seq: the seq number of the generic netlink report + */ struct binder_context { struct binder_node *binder_context_mgr_node; struct mutex context_mgr_node_lock; kuid_t binder_context_mgr_uid; const char *name; + struct genl_family genl_family; + u32 report_portid; + u32 report_flags; + atomic_t report_seq; }; =20 /** @@ -415,6 +432,8 @@ struct binder_ref { * @binderfs_entry: process-specific binderfs log file * @oneway_spam_detection_enabled: process enabled oneway spam detection * or not + * @report_flags: the categories of binder transactions that would + * be reported (see enum binder_report_flag). * * Bookkeeping structure for binder processes */ @@ -453,6 +472,7 @@ struct binder_proc { spinlock_t outer_lock; struct dentry *binderfs_entry; bool oneway_spam_detection_enabled; + u32 report_flags; }; =20 /** @@ -582,4 +602,15 @@ struct binder_object { }; }; =20 +struct binder_proc *binder_find_proc(int pid); + +int binder_genl_init(struct genl_family *family, const char *name); + +int binder_genl_set_report(struct binder_context *context, u32 pid, u32 fl= ags); + +bool binder_genl_report_enabled(struct binder_proc *proc, u32 mask); + +void binder_genl_send_report(struct binder_context *context, + struct binder_report *report, int len); + #endif /* _LINUX_BINDER_INTERNAL_H */ diff --git a/drivers/android/binder_trace.h b/drivers/android/binder_trace.h index fe38c6fc65d0..16e0a7efbe3a 100644 --- a/drivers/android/binder_trace.h +++ b/drivers/android/binder_trace.h @@ -423,6 +423,43 @@ TRACE_EVENT(binder_return, "unknown") ); =20 +TRACE_EVENT(binder_send_report, + TP_PROTO(const char *name, struct binder_report *report, int len), + TP_ARGS(name, report, len), + TP_STRUCT__entry( + __field(const char *, name) + __field(uint32_t, err) + __field(uint32_t, from_pid) + __field(uint32_t, from_tid) + __field(uint32_t, to_pid) + __field(uint32_t, to_tid) + __field(uint32_t, reply) + __field(uint32_t, flags) + __field(uint32_t, code) + __field(binder_size_t, data_size) + __field(uint32_t, len) + ), + TP_fast_assign( + __entry->name =3D name; + __entry->err =3D report->err; + __entry->from_pid =3D report->from_pid; + __entry->from_tid =3D report->from_tid; + __entry->to_pid =3D report->to_pid; + __entry->to_tid =3D report->to_tid; + __entry->reply =3D report->reply; + __entry->flags =3D report->flags; + __entry->code =3D report->code; + __entry->data_size =3D report->data_size; + __entry->len =3D len; + ), + TP_printk("%s: %d %d:%d -> %d:%d %s flags=3D0x08%x code=3D%d %llu %d", + __entry->name, __entry->err, __entry->from_pid, + __entry->from_tid, __entry->to_pid, __entry->to_tid, + __entry->reply ? "reply" : "", + __entry->flags, __entry->code, __entry->data_size, + __entry->len) +); + #endif /* _BINDER_TRACE_H */ =20 #undef TRACE_INCLUDE_PATH diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index ad1fa7abc323..b2c5b04bf2ab 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -207,6 +207,10 @@ static int binderfs_binder_device_create(struct inode = *ref_inode, fsnotify_create(root->d_inode, dentry); inode_unlock(d_inode(root)); =20 + ret =3D binder_genl_init(&device->context.genl_family, name); + if (ret < 0) + goto err; + return 0; =20 err: diff --git a/include/uapi/linux/android/binder.h b/include/uapi/linux/andro= id/binder.h index 1fd92021a573..19c49a2a0301 100644 --- a/include/uapi/linux/android/binder.h +++ b/include/uapi/linux/android/binder.h @@ -588,5 +588,137 @@ enum binder_driver_command_protocol { */ }; =20 +/* + * Name of binder generic netlink + */ +#define BINDER_GENL_FAMILY_NAME "binder" + +/* + * Version of binder generic netlink + */ +#define BINDER_GENL_VERSION 1 + +/* + * Used with BINDER_ENABLE_REPORT, defining what kind of binder transactio= ns + * should be reported to user space administration process. + */ +enum binder_report_flag { + /* + * Report failed binder transactions, + * when the sender gets BR_{FAILED|FROZEN|DEAD}_REPLY + */ + BINDER_REPORT_FAILED =3D 0x1, + + /* + * Report delayed async binder transactions due to frozen target, + * when the sender gets BR_TRANSACTION_PENDING_FROZEN. + */ + BINDER_REPORT_DELAYED =3D 0x2, + + /* + * Report spamming binder transactions, + * when the sender gets BR_ONEWAY_SPAM_SUSPECT. + */ + BINDER_REPORT_SPAM =3D 0x4, + + /* + * Report all of the above + */ + BINDER_REPORT_ALL =3D BINDER_REPORT_FAILED + | BINDER_REPORT_DELAYED + | BINDER_REPORT_SPAM, + + /* + * Enable the per-process flag, which overrides the global one. + */ + BINDER_REPORT_OVERRIDE =3D 0x8000000, +}; + +/* + * struct binder_report - reports an abnormal binder transaction + * @err: copy of binder_driver_return_protocol returned to the sender + * @from_pid: sender pid of the corresponding binder transaction + * @from_tid: sender tid of the corresponding binder transaction + * @to_pid: target pid of the corresponding binder transaction + * @to_tid: target tid of the corresponding binder transaction + * @reply: 1 means the txn is a reply, 0 otherwise + * @flags: copy of binder_transaction_data->flags + * @code: copy of binder_transaction_data->code + * @data_size: copy of binder_transaction_data->data_size + * + * When a binder transaction fails to reach the target process or is not + * delivered on time, an error command BR_XXX is returned from the kernel + * binder driver to the user space sender. This is considered an abnormal + * binder transaction. The most important information about this abnormal + * binder transaction will be packed into this binder_report struct and se= nt + * to the registered user space administration process via generic netlink. + */ +struct binder_report { + __u32 err; + __u32 from_pid; + __u32 from_tid; + __u32 to_pid; + __u32 to_tid; + __u32 reply; + __u32 flags; + __u32 code; + binder_size_t data_size; +}; + +/* + * The supported attributes of binder generic netlink. + */ +enum binder_genl_attr { + BINDER_GENL_ATTR_UNSPEC =3D 0, + + /* + * The attribute for BINDER_GENL_CMD_SET_REPORT and its REPLY. + * Contains payload u32 pid. + */ + BINDER_GENL_ATTR_PID =3D 1, + + /* + * The attribute for BINDER_GENL_CMD_SET_REPORT and its REPLY. + * Contains payload u32 report_flags;. + */ + BINDER_GENL_ATTR_FLAGS =3D 2, + + /* + * The attribute for BINDER_GENL_CMD_REPORT. + * Contains payload struct binder_report. + */ + BINDER_GENL_ATTR_REPORT =3D 3, + + BINDER_GENL_ATTR_MAX =3D BINDER_GENL_ATTR_REPORT, +}; + +/* + * The supported commands of binder generic netlink. + */ +enum binder_genl_cmd { + BINDER_GENL_CMD_UNSPEC =3D 0, + + /* + * The user space administrator process uses this command to set what + * kinds of binder transactions are reported via generic netlink. + */ + BINDER_GENL_CMD_SET_REPORT =3D 1, + + /* + * After receiving BINDER_GENL_SET_REPORT from the user space + * administrator process, the kernel binder driver uses this command + * to acknowledge the request. + */ + BINDER_GENL_CMD_REPLY =3D 2, + + /* + * After enabling binder report, the kernel binder driver uses this + * command to send the requested reports to the user space. + */ + BINDER_GENL_CMD_REPORT =3D 3, + + BINDER_GENL_CMD_MAX =3D BINDER_GENL_CMD_REPORT, +}; + #endif /* _UAPI_LINUX_BINDER_H */ =20 --=20 2.47.0.105.g07ac214952-goog From nobody Tue Nov 26 04:24:55 2024 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CAAF1FAC36 for ; Mon, 21 Oct 2024 18:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729535318; cv=none; b=HBiCof7jORMnCB9pndw1zmMWkM29A14NYBo6gcZz6cjwRVo1SSZ18dOia9yscfEVtAU56eYLYzReDYMkMt2jmLv0Ke4Pz1evuKrpxUFsNBHERVixum9jEhKESaEv2bmxAtNWnlQDmObT1sbPC5kEs8OQPfEqJDIBLovl9Toplxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729535318; c=relaxed/simple; bh=288K8iD25VCBZadItaqAJU62Kx+snliXLKLUCL81Sbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ECJJtoVtasBUrtIejBJkj8J2YtR6kdohuOhMi9cqfFKIn+MWIX+41kIuHaDE+k79ilkrkvPYYuoMQoNxaDI6Szg1b+9g577mau4RjfCgKJ2IMrbWahNaBEnU9erYi0vL34WKEJuChicSAE7HV9Qd+tKutgXJ6NZ+K8OHGUyrJ2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=nqkLxV8J; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="nqkLxV8J" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-20bb39d97d1so44333665ad.2 for ; Mon, 21 Oct 2024 11:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729535313; x=1730140113; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ni92t7Oip5Z7ABJzyJw4un2QcSnAoq45TsSsB24QvdI=; b=nqkLxV8J3m1pSEuq6ajaVsPcV9+8Uzqw8DR+X9mDXYPKYwMLoM0g4dpTl2HbvRF0ZB ijm6LBGM3vznf9DN6bZH9gkg050/qN1wSDVlttdgsrHsonhLxgxJJTyhwXgBxioaeCb8 f04ELXPjuV46O7R4i7kU03Uy2chlRiJauHLf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729535313; x=1730140113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ni92t7Oip5Z7ABJzyJw4un2QcSnAoq45TsSsB24QvdI=; b=EiLPdFmOlGZsX+wTdmsoV5443qi5alevhPNOlmV6m+lvyKgtE+3nR/cdV9InS7Jsrk 9v5VuLPCvzdZ+gf6aRgzblDtE9d2kyACTGDA1cSZcyxc5qwplV1ypgHNjB44Z+RRlPF8 4elmNvm7PXEvYaE9aHSXtMoTCJB5/+mn6ETKvOGUYgNOEYsyZhUVWg0SB7gLqKjwYRex tBtPji5FonH/brpZ63BkUTw3KmIfbYFF+wqQMzbKrFB6AqAu/Xm1T8Ce4J3aN3GnkIAz iLFgAnzncXBwEgK6SVUCeogQMVAMiopTMIW0kkKWWjY4v/bSsxH7xV3e+fWDqGSX0NBt 8Aog== X-Forwarded-Encrypted: i=1; AJvYcCW8oL2ykTldAEoUgKbzpmcTfmTHrfZPzfeAS9yGQc8DwLLA/Bh7j2JVUEpimMR7rmnaTRzmwwdoMKMsDsg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3MHhsH448Gkm4faF2lkPS7lMsJuzb32b6ASYIykkdZJNRbLWd RFWeroQrR7JpjHntf9/28eEguWM7ORpBnclSjZuLvvMGxPv+42SUN6jcOmNTvg== X-Google-Smtp-Source: AGHT+IEtpPM5qy5wWd09nhSDqFzMBCoj5PDpkTfazJrJFzjpSI76Or4hieKifGIsI6rO9AL9N8ks8Q== X-Received: by 2002:a17:902:cec7:b0:20c:a97d:cc5c with SMTP id d9443c01a7336-20e9487dfbemr11031055ad.6.1729535313468; Mon, 21 Oct 2024 11:28:33 -0700 (PDT) Received: from li-cloudtop.c.googlers.com.com (43.222.125.34.bc.googleusercontent.com. [34.125.222.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0f3c95sm28914195ad.253.2024.10.21.11.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 11:28:32 -0700 (PDT) From: Li Li To: dualli@google.com, corbet@lwn.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, donald.hunter@gmail.com, gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, brauner@kernel.org, cmllamas@google.com, surenb@google.com, arnd@arndb.de, masahiroy@kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, netdev@vger.kernel.org, hridya@google.com, smoreland@google.com Cc: kernel-team@android.com Subject: [PATCH v3 1/1] report binder txn errors via generic netlink Date: Mon, 21 Oct 2024 11:28:21 -0700 Message-ID: <20241021182821.1259487-3-dualli@chromium.org> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog In-Reply-To: <20241021182821.1259487-1-dualli@chromium.org> References: <20241021182821.1259487-1-dualli@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li Li Frozen tasks can't process binder transactions, so sync binder transactions will fail with BR_FROZEN_REPLY and async binder transactions will be queued in the kernel async binder buffer. As these queued async transactions accumulates over time, the async buffer will eventually be running out, denying all new transactions after that with BR_FAILED_REPLY. In addition to the above cases, different kinds of binder error codes might be returned to the sender. However, the core Linux, or Android, system administration process never knows what's actually happening. This patch introduces the Linux generic netlink messages into the binder driver so that the Linux/Android system administration process can listen to important events and take corresponding actions, like stopping a broken app from attacking the OS by sending huge amount of spamming binder transactions. The new binder genl sources and headers are automatically generated from the corresponding YAML spec. Don't modify them directly. Signed-off-by: Li Li --- Documentation/admin-guide/binder_genl.rst | 92 ++++++ Documentation/admin-guide/index.rst | 1 + Documentation/netlink/specs/binder_genl.yaml | 59 ++++ drivers/android/Kconfig | 1 + drivers/android/Makefile | 2 +- drivers/android/binder.c | 287 ++++++++++++++++++- drivers/android/binder_genl.c | 38 +++ drivers/android/binder_genl.h | 18 ++ drivers/android/binder_internal.h | 22 ++ drivers/android/binder_trace.h | 37 +++ drivers/android/binderfs.c | 4 + include/uapi/linux/android/binder.h | 31 ++ include/uapi/linux/android/binder_genl.h | 37 +++ 13 files changed, 625 insertions(+), 4 deletions(-) create mode 100644 Documentation/admin-guide/binder_genl.rst create mode 100644 Documentation/netlink/specs/binder_genl.yaml create mode 100644 drivers/android/binder_genl.c create mode 100644 drivers/android/binder_genl.h create mode 100644 include/uapi/linux/android/binder_genl.h diff --git a/Documentation/admin-guide/binder_genl.rst b/Documentation/admi= n-guide/binder_genl.rst new file mode 100644 index 000000000000..48a0ceab6552 --- /dev/null +++ b/Documentation/admin-guide/binder_genl.rst @@ -0,0 +1,92 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Generic Netlink for the Android Binder Driver (Binder Genl) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The Generic Netlink subsystem in the Linux kernel provides a generic way f= or +the Linux kernel to communicate to the user space applications. In the ker= nel +binder driver, it is used to report various kinds of binder transactions to +user space administration process. The binder driver allows multiple binder +devices and their corresponding binder contexts. Each binder context has a +independent Generic Netlink for security reason. To prevent untrusted user +applications from accessing the netlink data, the kernel driver uses unica= st +mode instead of multicast. + +Basically, the user space code use the "set" command to request what kinds +of binder transactions should be reported by the kernel binder driver. The +kernel binder driver use "reply" command to acknowledge the request. The +"set" command also register the current user space process to receive the +reports. When the user space process exits, the previous request will be +reset to prevent any potential leaks. + +Currently the binder driver can report binder trasnactiosn that "failed" +to reach the target process, or that are "delayed" due to the target proce= ss +being frozen by cgroup freezer, or that are considered "spam" according to +existing logic in binder_alloc.c. + +When the specified binder transactions happened, the binder driver uses the +"report" command to send a generic netlink message to the registered proce= ss, +containing the payload struct binder_report. + +More details about the flags, attributes and operations can be found at the +the doc sections in Documentations/netlink/specs/binder_genl.yaml and the +kernel-doc comments of the new source code in binder.{h|c}. + +Using Binder Genl +----------------- + +The Binder Genl can be used in the same way as any other generic netlink +drivers. The user space application uses a raw netlink socket to send comm= ands +to and receive packets from the kernel driver. + +NOTE: if the user applications that talks to the Binder Genl driver exits, +the kernel driver will automatically reset the configuration to the default +and stop sending more reports to prevent leaking memory. + +Usage example (user space pseudo code): + +:: + + // open netlink socket + int fd =3D socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + + // bind netlink socket + bind(fd, struct socketaddr); + + // get the family id of the binder genl + send(fd, CTRL_CMD_GETFAMILY, CTRL_ATTR_FAMILY_NAME, "binder"); + void *data =3D recv(CTRL_CMD_NEWFAMILY); + __u16 id =3D nla(data)[CTRL_ATTR_FAMILY_ID]; + + // enable per-context binder report + send(fd, id, BINDER_GENL_CMD_SET, 0, BINDER_GENL_FLAG_FAILED | + BINDER_GENL_FLAG_DELAYED); + + // confirm the per-context configuration + void *data =3D recv(fd, BINDER_GENL_CMD_REPLY); + __u32 pid =3D nla(data)[BINDER_GENL_ATTR_PID]; + __u32 flags =3D nla(data)[BINDER_GENL_ATTR_FLAGS]; + + // set optional per-process report, overriding the per-context one + send(fd, id, BINDER_GENL_CMD_SET, getpid(), + BINDER_GENL_FLAG_SPAM | BINDER_REPORT_OVERRIDE); + + // confirm the optional per-process configuration + void *data =3D recv(fd, BINDER_GENL_CMD_REPLY); + __u32 pid =3D nla(data)[BINDER_GENL_A_ATTR_PID]; + __u32 flags =3D nla(data)[BINDER_GENL_A_ATTR_FLAGS]; + + // wait and read all binder reports + while (running) { + void *data =3D recv(fd, BINDER_GENL_CMD_REPORT); + struct binder_report report =3D nla(data)[BINDER_GENL_A_ATTR_R= EPORT]; + + // process struct binder_report + do_something(&report); + } + + // clean up + send(fd, id, BINDER_GENL_CMD_SET, 0, 0); + send(fd, id, BINDER_GENL_CMD_SET, getpid(), 0); + close(fd); diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guid= e/index.rst index e85b1adf5908..b3b5cfadffe5 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -79,6 +79,7 @@ configure specific aspects of kernel behavior to your lik= ing. aoe/index auxdisplay/index bcache + binder_genl binderfs binfmt-misc blockdev/index diff --git a/Documentation/netlink/specs/binder_genl.yaml b/Documentation/n= etlink/specs/binder_genl.yaml new file mode 100644 index 000000000000..8479580a2856 --- /dev/null +++ b/Documentation/netlink/specs/binder_genl.yaml @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cla= use) + +name: binder_genl +protocol: genetlink + +doc: Netlink protocol to report binder transaction errors and warnings. + +uapi-header: linux/android/binder_genl.h + +definitions: + - + type: flags + name: flag + doc: Used with "set" and "reply" command below, defining what kind \ + of binder transactions should be reported to the user space \ + administration process. + value-start: 0 + entries: [ failed, delayed, spam, override ] + +attribute-sets: + - + name: attr + doc: The supported attributes of binder genl. + attributes: + - + name: pid + type: u32 + doc: Used by "set" and "reply" command below, indicating the \ + binder proc or context to set the flags. + - + name: flags + type: u32 + doc: Used by "set" and "reply" command below, indicating the \ + flags to set. + - + name: report + type: binary + doc: Used by "report" command below, containing struct binder_repo= rt. + +operations: + list: + - + name: set + doc: Set flags from user space, requesting what kinds of binder \ + transactions to report. + attribute-set: attr + + do: + request: ¶ms + attributes: + - pid + - flags + reply: *params + - + name: reply + doc: Acknowledge the above "set" request, echoing the same params. + - + name: report + doc: Send the requested binder transaction reports to user space. diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig index 07aa8ae0a058..e2fa620934e2 100644 --- a/drivers/android/Kconfig +++ b/drivers/android/Kconfig @@ -4,6 +4,7 @@ menu "Android" config ANDROID_BINDER_IPC bool "Android Binder IPC Driver" depends on MMU + depends on NET default n help Binder is used in Android for both communication between processes, diff --git a/drivers/android/Makefile b/drivers/android/Makefile index c9d3d0c99c25..d818447fbc4c 100644 --- a/drivers/android/Makefile +++ b/drivers/android/Makefile @@ -2,5 +2,5 @@ ccflags-y +=3D -I$(src) # needed for trace events =20 obj-$(CONFIG_ANDROID_BINDERFS) +=3D binderfs.o -obj-$(CONFIG_ANDROID_BINDER_IPC) +=3D binder.o binder_alloc.o +obj-$(CONFIG_ANDROID_BINDER_IPC) +=3D binder.o binder_alloc.o binder_genl.o obj-$(CONFIG_ANDROID_BINDER_IPC_SELFTEST) +=3D binder_alloc_selftest.o diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 978740537a1a..26941338c965 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -72,6 +72,7 @@ =20 #include =20 +#include "binder_genl.h" #include "binder_internal.h" #include "binder_trace.h" =20 @@ -2984,6 +2985,130 @@ static void binder_set_txn_from_error(struct binder= _transaction *t, int id, binder_thread_dec_tmpref(from); } =20 +/** + * binder_find_proc() - set binder report flags + * @pid: the target process + */ +static struct binder_proc *binder_find_proc(int pid) +{ + struct binder_proc *proc; + + mutex_lock(&binder_procs_lock); + hlist_for_each_entry(proc, &binder_procs, proc_node) { + if (proc->pid =3D=3D pid) { + mutex_unlock(&binder_procs_lock); + return proc; + } + } + mutex_unlock(&binder_procs_lock); + + return NULL; +} + +/** + * binder_genl_set_report() - set binder report flags + * @proc: the binder_proc calling the ioctl + * @pid: the target process + * @flags: the flags to set + * + * If pid is 0, the flags are applied to the whole binder context. + * Otherwise, the flags are applied to the specific process only. + */ +static int binder_genl_set_report(struct binder_context *context, u32 pid,= u32 flags) +{ + struct binder_proc *proc; + + if (flags !=3D (flags & (BINDER_GENL_FLAG_OVERRIDE + | BINDER_GENL_FLAG_FAILED + | BINDER_GENL_FLAG_DELAYED + | BINDER_GENL_FLAG_SPAM))) { + pr_err("Invalid binder report flags: %u\n", flags); + return -EINVAL; + } + + if (!pid) { + /* Set the global flags for the whole binder context */ + context->report_flags =3D flags; + } else { + /* Set the per-process flags */ + proc =3D binder_find_proc(pid); + if (!proc) { + pr_err("Invalid binder report pid %u\n", pid); + return -EINVAL; + } + + proc->report_flags =3D flags; + } + + return 0; +} + +/** + * binder_genl_report_enabled() - check if binder genl reports are enabled + * @proc: the binder_proc to check + * @mask: the categories of binder genl reports + * + * Returns true if certain binder genl reports are enabled for this binder + * proc (when per-process overriding takes effect) or context. + */ +static bool binder_genl_report_enabled(struct binder_proc *proc, u32 mask) +{ + struct binder_context *context =3D proc->context; + + if (!context->report_portid) + return false; + + if (proc->report_flags & BINDER_GENL_FLAG_OVERRIDE) + return (proc->report_flags & mask) !=3D 0; + else + return (context->report_flags & mask) !=3D 0; +} + +/** + * binder_genl_send_report() - send one binder genl report + * @context: the binder context + * @report: the binder genl report to send + * @len: the length of the report data + * + * Packs the report data into a BINDER_GENL_A_ATTR_REPORT packet and send = it. + */ +static void binder_genl_send_report(struct binder_context *context, + struct binder_report *report, int len) +{ + int ret; + struct sk_buff *skb; + void *hdr; + + trace_binder_send_report(context->name, report, len); + + skb =3D genlmsg_new(nla_total_size(len), GFP_KERNEL); + if (!skb) { + pr_err("Failed to alloc binder genl message\n"); + return; + } + + hdr =3D genlmsg_put(skb, 0, atomic_inc_return(&context->report_seq), + &context->genl_family, 0, BINDER_GENL_CMD_REPORT); + if (!hdr) { + pr_err("Failed to set binder genl header\n"); + kfree_skb(skb); + return; + } + + if (nla_put(skb, BINDER_GENL_A_ATTR_REPORT, len, report)) { + genlmsg_cancel(skb, hdr); + nlmsg_free(skb); + return; + } + + genlmsg_end(skb, hdr); + + ret =3D genlmsg_unicast(&init_net, skb, context->report_portid); + if (ret < 0) + pr_err("Failed to send binder genl message to %d: %d\n", + context->report_portid, ret); +} + static void binder_transaction(struct binder_proc *proc, struct binder_thread *thread, struct binder_transaction_data *tr, int reply, @@ -3678,10 +3803,25 @@ static void binder_transaction(struct binder_proc *= proc, return_error_line =3D __LINE__; goto err_copy_data_failed; } - if (t->buffer->oneway_spam_suspect) + if (t->buffer->oneway_spam_suspect) { tcomplete->type =3D BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT; - else + if (binder_genl_report_enabled(proc, BINDER_GENL_FLAG_SPAM)) { + struct binder_report report; + + report.err =3D BR_ONEWAY_SPAM_SUSPECT; + report.from_pid =3D proc->pid; + report.from_tid =3D thread->pid; + report.to_pid =3D target_proc ? target_proc->pid : 0; + report.to_tid =3D target_thread ? target_thread->pid : 0; + report.reply =3D reply; + report.flags =3D tr->flags; + report.code =3D tr->code; + report.data_size =3D tr->data_size; + binder_genl_send_report(context, &report, sizeof(report)); + } + } else { tcomplete->type =3D BINDER_WORK_TRANSACTION_COMPLETE; + } t->work.type =3D BINDER_WORK_TRANSACTION; =20 if (reply) { @@ -3731,8 +3871,24 @@ static void binder_transaction(struct binder_proc *p= roc, * process and is put in a pending queue, waiting for the target * process to be unfrozen. */ - if (return_error =3D=3D BR_TRANSACTION_PENDING_FROZEN) + if (return_error =3D=3D BR_TRANSACTION_PENDING_FROZEN) { tcomplete->type =3D BINDER_WORK_TRANSACTION_PENDING; + if (binder_genl_report_enabled(proc, BINDER_GENL_FLAG_DELAYED)) { + struct binder_report report; + + report.err =3D return_error; + report.from_pid =3D proc->pid; + report.from_tid =3D thread->pid; + report.to_pid =3D target_proc ? target_proc->pid : 0; + report.to_tid =3D target_thread ? target_thread->pid : 0; + report.reply =3D reply; + report.flags =3D tr->flags; + report.code =3D tr->code; + report.data_size =3D tr->data_size; + binder_genl_send_report(context, &report, + sizeof(report)); + } + } binder_enqueue_thread_work(thread, tcomplete); if (return_error && return_error !=3D BR_TRANSACTION_PENDING_FROZEN) @@ -3794,6 +3950,21 @@ static void binder_transaction(struct binder_proc *p= roc, binder_dec_node_tmpref(target_node); } =20 + if (binder_genl_report_enabled(proc, BINDER_GENL_FLAG_FAILED)) { + struct binder_report report; + + report.err =3D return_error; + report.from_pid =3D proc->pid; + report.from_tid =3D thread->pid; + report.to_pid =3D target_proc ? target_proc->pid : 0; + report.to_tid =3D target_thread ? target_thread->pid : 0; + report.reply =3D reply; + report.flags =3D tr->flags; + report.code =3D tr->code; + report.data_size =3D tr->data_size; + binder_genl_send_report(context, &report, sizeof(report)); + } + binder_debug(BINDER_DEBUG_FAILED_TRANSACTION, "%d:%d transaction %s to %d:%d failed %d/%d/%d, size %lld-%lld line= %d\n", proc->pid, thread->pid, reply ? "reply" : @@ -6114,6 +6285,11 @@ static int binder_release(struct inode *nodp, struct= file *filp) =20 binder_defer_work(proc, BINDER_DEFERRED_RELEASE); =20 + if (proc->pid =3D=3D proc->context->report_portid) { + proc->context->report_portid =3D 0; + proc->context->report_flags =3D 0; + } + return 0; } =20 @@ -6311,6 +6487,84 @@ binder_defer_work(struct binder_proc *proc, enum bin= der_deferred_state defer) mutex_unlock(&binder_deferred_lock); } =20 +/** + * binder_genl_nl_set_doit() - .doit handler for BINDER_GENL_CMD_SET + * @skb: the metadata struct passed from netlink driver + * @info: the generic netlink struct passed from netlink driver + * + * Implements the .doit function to process binder genl commands. + */ +int binder_genl_nl_set_doit(struct sk_buff *skb, struct genl_info *info) +{ + int len; + int portid; + u32 pid; + u32 flags; + void *hdr; + struct binder_context *context; + + /* Both attributes are required for BINDER_GENL_CMD_SET */ + if (!info->attrs[BINDER_GENL_A_ATTR_PID] || !info->attrs[BINDER_GENL_A_AT= TR_FLAGS]) { + pr_err("Attributes not set\n"); + return -EINVAL; + } + + portid =3D nlmsg_hdr(skb)->nlmsg_pid; + pid =3D nla_get_u32(info->attrs[BINDER_GENL_A_ATTR_PID]); + flags =3D nla_get_u32(info->attrs[BINDER_GENL_A_ATTR_FLAGS]); + context =3D container_of(info->family, struct binder_context, + genl_family); + + if (context->report_portid && context->report_portid !=3D portid) { + pr_err("No permission to set report flags from %u\n", portid); + return -EPERM; + } + + if (binder_genl_set_report(context, pid, flags) < 0) { + pr_err("Failed to set report flags %u for %u\n", flags, pid); + return -EINVAL; + } + + len =3D nla_total_size(sizeof(pid)) + nla_total_size(sizeof(flags)); + skb =3D genlmsg_new(len, GFP_KERNEL); + if (!skb) { + pr_err("Failed to alloc binder genl reply message\n"); + return -ENOMEM; + } + + hdr =3D genlmsg_put_reply(skb, info, info->family, 0, + BINDER_GENL_CMD_REPLY); + if (!hdr) + goto free_skb; + + if (nla_put_u32(skb, BINDER_GENL_A_ATTR_PID, pid)) + goto cancel_skb; + + if (nla_put_u32(skb, BINDER_GENL_A_ATTR_FLAGS, flags)) + goto cancel_skb; + + genlmsg_end(skb, hdr); + + if (genlmsg_reply(skb, info)) { + pr_err("Failed to send binder genl reply message\n"); + return -EFAULT; + } + + if (!context->report_portid) + context->report_portid =3D portid; + + return 0; + +cancel_skb: + pr_err("Failed to add genl header to reply message\n"); + genlmsg_cancel(skb, hdr); + +free_skb: + pr_err("Failed to add genl attribute to reply message\n"); + nlmsg_free(skb); + return -EMSGSIZE; +} + static void print_binder_transaction_ilocked(struct seq_file *m, struct binder_proc *proc, const char *prefix, @@ -6894,6 +7148,28 @@ const struct binder_debugfs_entry binder_debugfs_ent= ries[] =3D { {} /* terminator */ }; =20 +/** + * binder_genl_init() - initialize binder generic netlink + * @family: the generic netlink family + * @name: the binder device name + * + * Registers the binder generic netlink family. + */ +int binder_genl_init(struct genl_family *family, const char *name) +{ + int ret; + + memcpy(family, &binder_genl_nl_family, sizeof(*family)); + strscpy(family->name, name, GENL_NAMSIZ); + ret =3D genl_register_family(family); + if (ret) { + pr_err("Failed to register binder genl: %s\n", name); + return ret; + } + + return 0; +} + static int __init init_binder_device(const char *name) { int ret; @@ -6920,6 +7196,11 @@ static int __init init_binder_device(const char *nam= e) =20 hlist_add_head(&binder_device->hlist, &binder_devices); =20 + binder_device->context.report_seq =3D (atomic_t)ATOMIC_INIT(0); + ret =3D binder_genl_init(&binder_device->context.genl_family, name); + if (ret < 0) + kfree(binder_device); + return ret; } =20 diff --git a/drivers/android/binder_genl.c b/drivers/android/binder_genl.c new file mode 100644 index 000000000000..c9b9bc5cdfb6 --- /dev/null +++ b/drivers/android/binder_genl.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder_genl.yaml */ +/* YNL-GEN kernel source */ + +#include +#include + +#include "binder_genl.h" + +#include + +/* BINDER_GENL_CMD_SET - do */ +static const struct nla_policy binder_genl_set_nl_policy[BINDER_GENL_A_ATT= R_FLAGS + 1] =3D { + [BINDER_GENL_A_ATTR_PID] =3D { .type =3D NLA_U32, }, + [BINDER_GENL_A_ATTR_FLAGS] =3D { .type =3D NLA_U32, }, +}; + +/* Ops table for binder_genl */ +static const struct genl_split_ops binder_genl_nl_ops[] =3D { + { + .cmd =3D BINDER_GENL_CMD_SET, + .doit =3D binder_genl_nl_set_doit, + .policy =3D binder_genl_set_nl_policy, + .maxattr =3D BINDER_GENL_A_ATTR_FLAGS, + .flags =3D GENL_CMD_CAP_DO, + }, +}; + +struct genl_family binder_genl_nl_family __ro_after_init =3D { + .name =3D BINDER_GENL_FAMILY_NAME, + .version =3D BINDER_GENL_FAMILY_VERSION, + .netnsok =3D true, + .parallel_ops =3D true, + .module =3D THIS_MODULE, + .split_ops =3D binder_genl_nl_ops, + .n_split_ops =3D ARRAY_SIZE(binder_genl_nl_ops), +}; diff --git a/drivers/android/binder_genl.h b/drivers/android/binder_genl.h new file mode 100644 index 000000000000..9d68c155b7c4 --- /dev/null +++ b/drivers/android/binder_genl.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder_genl.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_BINDER_GENL_GEN_H +#define _LINUX_BINDER_GENL_GEN_H + +#include +#include + +#include + +int binder_genl_nl_set_doit(struct sk_buff *skb, struct genl_info *info); + +extern struct genl_family binder_genl_nl_family; + +#endif /* _LINUX_BINDER_GENL_GEN_H */ diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_int= ernal.h index f8d6be682f23..4abc8e3940c3 100644 --- a/drivers/android/binder_internal.h +++ b/drivers/android/binder_internal.h @@ -12,15 +12,32 @@ #include #include #include +#include #include #include "binder_alloc.h" #include "dbitmap.h" =20 +/** + * struct binder_context - information about a binder domain + * @binder_context_mgr_node: the context manager + * @context_mgr_node_lock: the lock protecting the above context manager= node + * @binder_context_mgr_uid: the uid of the above context manager + * @name: the name of the binder device + * @genl_family: the generic netlink family + * @report_portid: the netlink socket to receive binder reports + * @report_flags: the categories of binder transactions that wo= uld + * be reported (see enum binder_report_flag). + * @report_seq: the seq number of the generic netlink report + */ struct binder_context { struct binder_node *binder_context_mgr_node; struct mutex context_mgr_node_lock; kuid_t binder_context_mgr_uid; const char *name; + struct genl_family genl_family; + u32 report_portid; + u32 report_flags; + atomic_t report_seq; }; =20 /** @@ -415,6 +432,8 @@ struct binder_ref { * @binderfs_entry: process-specific binderfs log file * @oneway_spam_detection_enabled: process enabled oneway spam detection * or not + * @report_flags: the categories of binder transactions that would + * be reported (see enum binder_report_flag). * * Bookkeeping structure for binder processes */ @@ -453,6 +472,7 @@ struct binder_proc { spinlock_t outer_lock; struct dentry *binderfs_entry; bool oneway_spam_detection_enabled; + u32 report_flags; }; =20 /** @@ -582,4 +602,6 @@ struct binder_object { }; }; =20 +int binder_genl_init(struct genl_family *family, const char *name); + #endif /* _LINUX_BINDER_INTERNAL_H */ diff --git a/drivers/android/binder_trace.h b/drivers/android/binder_trace.h index fe38c6fc65d0..16e0a7efbe3a 100644 --- a/drivers/android/binder_trace.h +++ b/drivers/android/binder_trace.h @@ -423,6 +423,43 @@ TRACE_EVENT(binder_return, "unknown") ); =20 +TRACE_EVENT(binder_send_report, + TP_PROTO(const char *name, struct binder_report *report, int len), + TP_ARGS(name, report, len), + TP_STRUCT__entry( + __field(const char *, name) + __field(uint32_t, err) + __field(uint32_t, from_pid) + __field(uint32_t, from_tid) + __field(uint32_t, to_pid) + __field(uint32_t, to_tid) + __field(uint32_t, reply) + __field(uint32_t, flags) + __field(uint32_t, code) + __field(binder_size_t, data_size) + __field(uint32_t, len) + ), + TP_fast_assign( + __entry->name =3D name; + __entry->err =3D report->err; + __entry->from_pid =3D report->from_pid; + __entry->from_tid =3D report->from_tid; + __entry->to_pid =3D report->to_pid; + __entry->to_tid =3D report->to_tid; + __entry->reply =3D report->reply; + __entry->flags =3D report->flags; + __entry->code =3D report->code; + __entry->data_size =3D report->data_size; + __entry->len =3D len; + ), + TP_printk("%s: %d %d:%d -> %d:%d %s flags=3D0x08%x code=3D%d %llu %d", + __entry->name, __entry->err, __entry->from_pid, + __entry->from_tid, __entry->to_pid, __entry->to_tid, + __entry->reply ? "reply" : "", + __entry->flags, __entry->code, __entry->data_size, + __entry->len) +); + #endif /* _BINDER_TRACE_H */ =20 #undef TRACE_INCLUDE_PATH diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index ad1fa7abc323..b2c5b04bf2ab 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -207,6 +207,10 @@ static int binderfs_binder_device_create(struct inode = *ref_inode, fsnotify_create(root->d_inode, dentry); inode_unlock(d_inode(root)); =20 + ret =3D binder_genl_init(&device->context.genl_family, name); + if (ret < 0) + goto err; + return 0; =20 err: diff --git a/include/uapi/linux/android/binder.h b/include/uapi/linux/andro= id/binder.h index 1fd92021a573..d95776448db9 100644 --- a/include/uapi/linux/android/binder.h +++ b/include/uapi/linux/android/binder.h @@ -588,5 +588,36 @@ enum binder_driver_command_protocol { */ }; =20 +/* + * struct binder_report - reports an abnormal binder transaction + * @err: copy of binder_driver_return_protocol returned to the sender + * @from_pid: sender pid of the corresponding binder transaction + * @from_tid: sender tid of the corresponding binder transaction + * @to_pid: target pid of the corresponding binder transaction + * @to_tid: target tid of the corresponding binder transaction + * @reply: 1 means the txn is a reply, 0 otherwise + * @flags: copy of binder_transaction_data->flags + * @code: copy of binder_transaction_data->code + * @data_size: copy of binder_transaction_data->data_size + * + * When a binder transaction fails to reach the target process or is not + * delivered on time, an error command BR_XXX is returned from the kernel + * binder driver to the user space sender. This is considered an abnormal + * binder transaction. The most important information about this abnormal + * binder transaction will be packed into this binder_report struct and se= nt + * to the registered user space administration process via generic netlink. + */ +struct binder_report { + __u32 err; + __u32 from_pid; + __u32 from_tid; + __u32 to_pid; + __u32 to_tid; + __u32 reply; + __u32 flags; + __u32 code; + binder_size_t data_size; +}; + #endif /* _UAPI_LINUX_BINDER_H */ =20 diff --git a/include/uapi/linux/android/binder_genl.h b/include/uapi/linux/= android/binder_genl.h new file mode 100644 index 000000000000..ef5289133be5 --- /dev/null +++ b/include/uapi/linux/android/binder_genl.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder_genl.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_BINDER_GENL_H +#define _UAPI_LINUX_BINDER_GENL_H + +#define BINDER_GENL_FAMILY_NAME "binder_genl" +#define BINDER_GENL_FAMILY_VERSION 1 + +enum binder_genl_flag { + BINDER_GENL_FLAG_FAILED =3D 1, + BINDER_GENL_FLAG_DELAYED =3D 2, + BINDER_GENL_FLAG_SPAM =3D 4, + BINDER_GENL_FLAG_OVERRIDE =3D 8, +}; + +enum { + BINDER_GENL_A_ATTR_PID =3D 1, + BINDER_GENL_A_ATTR_FLAGS, + BINDER_GENL_A_ATTR_REPORT, + + __BINDER_GENL_A_ATTR_MAX, + BINDER_GENL_A_ATTR_MAX =3D (__BINDER_GENL_A_ATTR_MAX - 1) +}; + +enum { + BINDER_GENL_CMD_SET =3D 1, + BINDER_GENL_CMD_REPLY, + BINDER_GENL_CMD_REPORT, + + __BINDER_GENL_CMD_MAX, + BINDER_GENL_CMD_MAX =3D (__BINDER_GENL_CMD_MAX - 1) +}; + +#endif /* _UAPI_LINUX_BINDER_GENL_H */ --=20 2.47.0.105.g07ac214952-goog