All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v9 0/1] binder: report txn errors via generic netlink
@ 2024-12-09 19:22 Li Li
  2024-12-09 19:22 ` [PATCH net-next v9 1/1] " Li Li
  0 siblings, 1 reply; 8+ messages in thread
From: Li Li @ 2024-12-09 19:22 UTC (permalink / raw)
  To: dualli, corbet, davem, edumazet, kuba, pabeni, donald.hunter,
	gregkh, arve, tkjos, maco, joel, brauner, cmllamas, surenb, arnd,
	masahiroy, bagasdotme, horms, linux-kernel, linux-doc, netdev,
	hridya, smoreland
  Cc: kernel-team

From: Li Li <dualli@google.com>

It's a known issue that neither the frozen processes nor the system
administration process of the OS can correctly deal with failed binder
transactions. The reason is that there's no reliable way for the user
space administration process to fetch the binder errors from the kernel
binder driver.

Android is such an OS suffering from this issue. Since cgroup freezer
was used to freeze user applications to save battery, innocent frozen
apps have to be killed when they receive sync binder transactions or
when their async binder buffer is running out.

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 transactiions.

The 1st version uses a global generic netlink for all binder contexts,
raising potential security concerns. There were a few other feedbacks
like request to kernel docs and test code. The thread can be found at
https://lore.kernel.org/lkml/20240812211844.4107494-1-dualli@chromium.org/

The 2nd version fixes those issues and has been tested on the latest
version of AOSP. See https://r.android.com/3305462 for how userspace is
going to use this feature and the test code. It can be found at
https://lore.kernel.org/lkml/20241011064427.1565287-1-dualli@chromium.org/

The 3rd version replaces the handcrafted netlink source code with the
netlink protocal specs in YAML. It also fixes the documentation issues.
https://lore.kernel.org/lkml/20241021182821.1259487-1-dualli@chromium.org/

The 4th version just containsi trivial fixes, making the subject of the
patch aligned with the subject of the cover letter.
https://lore.kernel.org/lkml/20241021191233.1334897-1-dualli@chromium.org/

The 5th version incorporates the suggested fixes to the kernel doc and
the init function. It also removes the unsupported uapi-header in YAML
that contains "/" for subdirectory.
https://lore.kernel.org/lkml/20241025075102.1785960-1-dualli@chromium.org/

The 6th version has some trivial kernel doc fixes, without modifying
any other source code.
https://lore.kernel.org/lkml/20241028101952.775731-1-dualli@chromium.org/

The 7th version breaks the binary struct netlink message into individual
attributes to better support automatic error checking. Thanks Jakub for
improving ynl-gen.
https://lore.kernel.org/all/20241031092504.840708-1-dualli@chromium.org/

The 8th version solves the multi-genl-family issue by demuxing the
messages based on a new context attribute. It also improves the YAML
spec to be consistent with netlink tradition. A Huge 'Thank You' to
Jakub who taught me a lot about the netlink protocol!
https://lore.kernel.org/all/20241113193239.2113577-1-dualli@chromium.org/

The 9th version only contains a few trivial fixes, removing a redundant
pr_err and unnecessary payload check. The ynl-gen patch to allow uapi
header in sub-dirs has been merged so it's no longer included in this
patch set.

v1: add a global binder genl socket for all contexts
v2: change to per-context binder genl for security reason
    replace the new ioctl with a netlink command
    add corresponding doc Documentation/admin-guide/binder_genl.rst
    add user space test code in AOSP
v3: use YNL spec (./tools/net/ynl/ynl-regen.sh)
    fix documentation index
v4: change the subject of the patch and remove unsed #if 0
v5: improve the kernel doc and the init function
    remove unsupported uapi-header in YAML
v6: fix some trivial kernel doc issues
v7: break the binary struct binder_report into individual attributes
v8: use multiplex netlink message in a unified netlink family
    improve the YAML spec to be consistent with netlink tradition
v9: remove unnecessary check to netlink flags and message payloads.

Li Li (1):
  binder: report txn errors via generic netlink

 Documentation/admin-guide/binder_genl.rst    |  96 +++++++
 Documentation/admin-guide/index.rst          |   1 +
 Documentation/netlink/specs/binder_genl.yaml | 108 ++++++++
 drivers/android/Kconfig                      |   1 +
 drivers/android/Makefile                     |   2 +-
 drivers/android/binder.c                     | 277 ++++++++++++++++++-
 drivers/android/binder_genl.c                |  39 +++
 drivers/android/binder_genl.h                |  18 ++
 drivers/android/binder_internal.h            |  27 +-
 drivers/android/binder_trace.h               |  35 +++
 drivers/android/binderfs.c                   |   2 +
 include/uapi/linux/android/binder_genl.h     |  55 ++++
 12 files changed, 655 insertions(+), 6 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


base-commit: 6145fefc1e42c1895c0c1c2c8593de2c085d8c56
-- 
2.47.0.338.g60cca15819-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH net-next v9 1/1] binder: report txn errors via generic netlink
@ 2024-12-10 16:50 kernel test robot
  0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2024-12-10 16:50 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Julia Lawall

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20241209192247.3371436-2-dualli@chromium.org>
References: <20241209192247.3371436-2-dualli@chromium.org>
TO: Li Li <dualli@chromium.org>
TO: dualli@google.com
TO: corbet@lwn.net
TO: davem@davemloft.net
TO: edumazet@google.com
TO: kuba@kernel.org
TO: pabeni@redhat.com
TO: donald.hunter@gmail.com
TO: gregkh@linuxfoundation.org
TO: arve@android.com
TO: tkjos@android.com
TO: maco@android.com
TO: joel@joelfernandes.org
TO: brauner@kernel.org
TO: cmllamas@google.com
TO: surenb@google.com
TO: arnd@arndb.de
TO: masahiroy@kernel.org
TO: bagasdotme@gmail.com
TO: horms@kernel.org
TO: linux-kernel@vger.kernel.org
TO: linux-doc@vger.kernel.org
TO: netdev@vger.kernel.org
TO: hridya@google.com
TO: smoreland@google.com
CC: kernel-team@android.com

Hi Li,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 6145fefc1e42c1895c0c1c2c8593de2c085d8c56]

url:    https://github.com/intel-lab-lkp/linux/commits/Li-Li/binder-report-txn-errors-via-generic-netlink/20241210-032559
base:   6145fefc1e42c1895c0c1c2c8593de2c085d8c56
patch link:    https://lore.kernel.org/r/20241209192247.3371436-2-dualli%40chromium.org
patch subject: [PATCH net-next v9 1/1] binder: report txn errors via generic netlink
:::::: branch date: 21 hours ago
:::::: commit date: 21 hours ago
config: x86_64-randconfig-102-20241210 (https://download.01.org/0day-ci/archive/20241211/202412110006.vSu6pw9e-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Julia Lawall <julia.lawall@inria.fr>
| Closes: https://lore.kernel.org/r/202412110006.vSu6pw9e-lkp@intel.com/

cocci warnings: (new ones prefixed by >>)
>> drivers/android/binder.c:6535:31-57: WARNING avoid newline at end of message in NL_SET_ERR_MSG

vim +6535 drivers/android/binder.c

355b0502f6efea0 drivers/staging/android/binder.c Greg Kroah-Hartman 2011-11-30  6509  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6510  /**
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6511   * binder_genl_nl_set_doit() - .doit handler for BINDER_GENL_CMD_SET
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6512   * @skb:	the metadata struct passed from netlink driver
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6513   * @info:	the generic netlink struct passed from netlink driver
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6514   *
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6515   * Implements the .doit function to process binder genl commands.
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6516   */
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6517  int binder_genl_nl_set_doit(struct sk_buff *skb, struct genl_info *info)
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6518  {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6519  	int portid;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6520  	u32 pid;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6521  	u32 flags;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6522  	void *hdr;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6523  	struct binder_device *device;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6524  	struct binder_context *context = NULL;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6525  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6526  	hlist_for_each_entry(device, &binder_devices, hlist) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6527  		if (!nla_strcmp(info->attrs[BINDER_GENL_A_CMD_CONTEXT],
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6528  				device->context.name)) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6529  			context = &device->context;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6530  			break;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6531  		}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6532  	}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6533  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6534  	if (!context) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09 @6535  		NL_SET_ERR_MSG(info->extack, "Unknown binder context\n");
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6536  		return -EINVAL;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6537  	}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6538  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6539  	portid = nlmsg_hdr(skb)->nlmsg_pid;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6540  	pid = nla_get_u32(info->attrs[BINDER_GENL_A_CMD_PID]);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6541  	flags = nla_get_u32(info->attrs[BINDER_GENL_A_CMD_FLAGS]);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6542  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6543  	if (context->report_portid && context->report_portid != portid) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6544  		NL_SET_ERR_MSG_FMT(info->extack,
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6545  				   "No permission to set flags from %d\n",
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6546  				   portid);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6547  		return -EPERM;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6548  	}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6549  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6550  	if (binder_genl_set_report(context, pid, flags) < 0) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6551  		pr_err("Failed to set report flags %u for %u\n", flags, pid);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6552  		return -EINVAL;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6553  	}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6554  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6555  	skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6556  	if (!skb) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6557  		pr_err("Failed to alloc binder genl reply message\n");
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6558  		return -ENOMEM;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6559  	}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6560  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6561  	hdr = genlmsg_iput(skb, info);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6562  	if (!hdr)
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6563  		goto free_skb;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6564  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6565  	if (nla_put_string(skb, BINDER_GENL_A_CMD_CONTEXT, context->name) ||
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6566  	    nla_put_u32(skb, BINDER_GENL_A_CMD_PID, pid) ||
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6567  	    nla_put_u32(skb, BINDER_GENL_A_CMD_FLAGS, flags))
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6568  		goto cancel_skb;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6569  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6570  	genlmsg_end(skb, hdr);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6571  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6572  	if (genlmsg_reply(skb, info)) {
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6573  		pr_err("Failed to send binder genl reply message\n");
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6574  		return -EFAULT;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6575  	}
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6576  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6577  	if (!context->report_portid)
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6578  		context->report_portid = portid;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6579  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6580  	return 0;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6581  
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6582  cancel_skb:
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6583  	pr_err("Failed to add reply attributes to binder genl message\n");
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6584  	genlmsg_cancel(skb, hdr);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6585  free_skb:
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6586  	pr_err("Free binder genl reply message on error\n");
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6587  	nlmsg_free(skb);
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6588  	return -EMSGSIZE;
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6589  }
86bd3e8e38707ae drivers/android/binder.c         Li Li              2024-12-09  6590  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-12-10 16:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-09 19:22 [PATCH net-next v9 0/1] binder: report txn errors via generic netlink Li Li
2024-12-09 19:22 ` [PATCH net-next v9 1/1] " Li Li
2024-12-10  0:44   ` Carlos Llamas
2024-12-10  1:26     ` Li Li
2024-12-10  3:16       ` Carlos Llamas
2024-12-10  3:31       ` Carlos Llamas
2024-12-10 11:35   ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2024-12-10 16:50 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.