From patchwork Mon Mar 3 20:02:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Li X-Patchwork-Id: 13999391 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 903DF235360 for ; Mon, 3 Mar 2025 20:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741032151; cv=none; b=sQlPuaXrqQLJ4WGtBmk7EPCqZ8dFOsUtg0qfxOX2IZVXyZ+3DAOf3nudMgO8jlgBr1ptuXrprzEQblOzFwETJnSY2AG6j0Dh85oldVGTLd/r/Svq88MeuAwQ5ECzeNUSoJJJx4xevfyoUhyBnhI8MixmXntcOf8gXbV9HEecT7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741032151; c=relaxed/simple; bh=/0ngzQtMnbW5Of4zFlh4yOH6BKkIsaKt9jM90aTRXpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N1Pc/BdgMZUSd5aY0DQz3F97P1agVNp8giPULDNSDII7fP+zR9dVLLhXzhmI81rFFYGjnAnH//tEIy0WU53Wv+v9RlhVVy9iON7NksdfR+L8qRR9bBM2HBfdh1p1q9eEIdoJM1Gw0wTF211UqF+Ygmf6PEi4PsPuzwA8QiY8WhQ= 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=kAUR+DwR; arc=none smtp.client-ip=209.85.214.171 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="kAUR+DwR" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-223a7065ff8so41460595ad.0 for ; Mon, 03 Mar 2025 12:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1741032148; x=1741636948; 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=0Y/4/pd1k6dHTWvdS5kPevXrcIKWux8yVsmsyCQC0NE=; b=kAUR+DwRhrfQtXY+UfA9F7F4/tUHWTrwUFFZHPztmKytpMCXfy5/kblnEt+42lMddS hus2t8MUnY33JVew8xTwhqS11BAd7ZiZMUQUG/79LyHK+cWZHgQPTOnXgFrcs8zqfUpc TQ94bhwf8/gOsGwpvfgi8NIKyAfm/JM0dQfUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741032148; x=1741636948; 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=0Y/4/pd1k6dHTWvdS5kPevXrcIKWux8yVsmsyCQC0NE=; b=gDwTs0JNA/YJnFQOXUWRiIo0tes1QjcmSQLrmmVT1Nwuip8Crqxs2QKqg2Dqz6cS0i z8201ok/rOOjgeWzp+fW4AWHc+kL+rp9PIBd4mClJ3P4yTa4ihIwf+b3G9t+jdUj08Eo /1vUROm+G+MZToAu86VBvNHoW3USOIj9tUMiZO+yNeKUIgdPwlmXm1c7+G+9UQXsOd79 Tbwov/xU7EKY8q7vLO7bL2i8FxyPUJKBOTFMgKRCIDW/01JERpk2h9fTQNDriwDXpg8d FLvxMRH7TIm+dsa89znI3nBTsoX/0bNuZKEhhk/IimGZkI3KKmv1+Z3LbjfZihusQghW 76TQ== X-Forwarded-Encrypted: i=1; AJvYcCVrpM3njZzmPMAd4zOPQ1PxyKet6W0UcxX5OPMosTR6cW5hvaV6knl0ETxb/ucBqyeLrIdnmQU=@vger.kernel.org X-Gm-Message-State: AOJu0YwTqm1xvXJxyVCZS1yuCOO7mUPk3SBaVYP/5Y3MgYGXza39bE9a fjNQxpLHxgv8iy9ToxuLRofEnlpMUiWQDZRpv2oi1mRgz3s7HER6F9wS7+NDqQ== X-Gm-Gg: ASbGncv9a5v3Gwzz3BimRVP47HZHFrpg8eo3Y3cwKtzBMOCUkgaKwIHpPxt8E1QatCm YLKXTPHe9+qZS7EeqIPVH0lSTUcMa/OzBJOFCb9SIo/rlhtrlgE32XScrZ6JlZ4oF/KBXuXW8xw wdhdOfTRROK78KK+Bx7/TUKJNhiN9Dh8oLDX9gtfONmuqfsrODJiyIjWI2SIAAvXkm3wLAoVy8q ngvVa4C6AqQZ+mThIP+ekxecwFy65N9tL9ZwsVlJ9o+DN8PnZEZKClPpKu+Rzwl3nRwwa5142QG t9IZ7+DKKjqWzAOLN8TGkQKghwgcSFg2GPTcsubs2+S2gtGPuBgPSdrilS3AhIMQYSFruldzdX+ OW+uaUwwJytliyfsd0+v98SBF03fRjw0= X-Google-Smtp-Source: AGHT+IHegT8hbV9Z9yYIqmC3KTe9PJwBJ6oCiv6zYuQs75m5txHhScRzpeb1cwpadUzfBOJOdsswzQ== X-Received: by 2002:a17:902:ea0c:b0:21f:74ec:1ff0 with SMTP id d9443c01a7336-22369258a3emr249021355ad.32.1741032147852; Mon, 03 Mar 2025 12:02:27 -0800 (PST) Received: from li-cloudtop.c.googlers.com.com (4.198.125.34.bc.googleusercontent.com. [34.125.198.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223504dc4b4sm81233875ad.171.2025.03.03.12.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 12:02:27 -0800 (PST) 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, omosnace@redhat.com, shuah@kernel.org, arnd@arndb.de, masahiroy@kernel.org, bagasdotme@gmail.com, horms@kernel.org, tweek@google.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, netdev@vger.kernel.org, selinux@vger.kernel.org, hridya@google.com Cc: smoreland@google.com, ynaffit@google.com, kernel-team@android.com Subject: [PATCH v16 1/3] lsm, selinux: Add setup_report permission to binder Date: Mon, 3 Mar 2025 12:02:10 -0800 Message-ID: <20250303200212.3294679-2-dualli@chromium.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303200212.3294679-1-dualli@chromium.org> References: <20250303200212.3294679-1-dualli@chromium.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: ThiĆ©baud Weksteen Introduce a new permission "setup_report" to the "binder" class. This persmission controls the ability to set up the binder generic netlink driver to report certain binder transactions. Signed-off-by: ThiĆ©baud Weksteen Signed-off-by: Li Li --- include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 ++++++ security/security.c | 13 +++++++++++++ security/selinux/hooks.c | 7 +++++++ security/selinux/include/classmap.h | 3 ++- 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 2bf909fa3394..395528de689f 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -33,6 +33,7 @@ LSM_HOOK(int, 0, binder_transfer_binder, const struct cred *from, const struct cred *to) LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from, const struct cred *to, const struct file *file) +LSM_HOOK(int, 0, binder_setup_report, const struct cred *to) LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child, unsigned int mode) LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent) diff --git a/include/linux/security.h b/include/linux/security.h index 1545d515a66b..b3c01254023e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -338,6 +338,7 @@ int security_binder_transfer_binder(const struct cred *from, const struct cred *to); int security_binder_transfer_file(const struct cred *from, const struct cred *to, const struct file *file); +int security_binder_setup_report(const struct cred *to); int security_ptrace_access_check(struct task_struct *child, unsigned int mode); int security_ptrace_traceme(struct task_struct *parent); int security_capget(const struct task_struct *target, @@ -657,6 +658,11 @@ static inline int security_binder_transfer_file(const struct cred *from, return 0; } +static inline int security_binder_setup_report(const struct cred *to) +{ + return 0; +} + static inline int security_ptrace_access_check(struct task_struct *child, unsigned int mode) { diff --git a/security/security.c b/security/security.c index 8aa839232c73..382e3bbab215 100644 --- a/security/security.c +++ b/security/security.c @@ -1043,6 +1043,19 @@ int security_binder_transfer_file(const struct cred *from, return call_int_hook(binder_transfer_file, from, to, file); } +/** + * security_binder_setup_report() - Check if process allowed to set up binder reports. + * @to: receiving process + * + * Check whether @to is allowed to set up binder reports. + * + * Return: Returns 0 if permission is granted. + */ +int security_binder_setup_report(const struct cred *to) +{ + return call_int_hook(binder_setup_report, to); +} + /** * security_ptrace_access_check() - Check if tracing is allowed * @child: target process diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 0d958f38ff9f..2fafa8feafdf 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2092,6 +2092,12 @@ static int selinux_binder_transfer_file(const struct cred *from, &ad); } +static int selinux_binder_setup_report(const struct cred *to) +{ + return avc_has_perm(current_sid(), cred_sid(to), SECCLASS_BINDER, + BINDER__SETUP_REPORT, NULL); +} + static int selinux_ptrace_access_check(struct task_struct *child, unsigned int mode) { @@ -7217,6 +7223,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = { LSM_HOOK_INIT(binder_transaction, selinux_binder_transaction), LSM_HOOK_INIT(binder_transfer_binder, selinux_binder_transfer_binder), LSM_HOOK_INIT(binder_transfer_file, selinux_binder_transfer_file), + LSM_HOOK_INIT(binder_setup_report, selinux_binder_setup_report), LSM_HOOK_INIT(ptrace_access_check, selinux_ptrace_access_check), LSM_HOOK_INIT(ptrace_traceme, selinux_ptrace_traceme), diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index 04a9b480885e..156741f1ca3f 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -135,7 +135,8 @@ const struct security_class_mapping secclass_map[] = { { "kernel_service", { "use_as_override", "create_files_as", NULL } }, { "tun_socket", { COMMON_SOCK_PERMS, "attach_queue", NULL } }, { "binder", - { "impersonate", "call", "set_context_mgr", "transfer", NULL } }, + { "impersonate", "call", "set_context_mgr", "transfer", + "setup_report", NULL } }, { "cap_userns", { COMMON_CAP_PERMS, NULL } }, { "cap2_userns", { COMMON_CAP2_PERMS, NULL } }, { "sctp_socket", From patchwork Mon Mar 3 20:02:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Li X-Patchwork-Id: 13999392 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 1E44E2356DF for ; Mon, 3 Mar 2025 20:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741032154; cv=none; b=IufyYZNZjbUHxAT59HdIfYtMQKpqcNtquC34tLLKm1SbQ/tgBYHJP/SjNGPHqTIYGM2QSgmQEHdo0+Gl6i02DkyUurF5ahL7RY3yOWHyo89iJ2bVSq7wI9/ZyhACWwF4Uah5v7ypdxEoQeRtis/qO8qefOpi7yQ5fxn20nHpBWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741032154; c=relaxed/simple; bh=sOCh27P1/msCBLx1Vq1a3LnVe7kA5pRxYlw4QL/NqOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vstcvm2pffdkLU74ELzG9ETYNVKwxcv8hVHC/YX7NMvSfOdM2KU3O36Av3unM9DG8XUqALc30f8yeEMMX4QP2hl5z1Osmj5u40doYD+1i7Pi6EOh9s1Uiaz0gy1hqxjKtJuVmyRFZnMlQTiaJOKOga6okwx0rvoJKymgmCyVBfc= 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=XLDggVnP; arc=none smtp.client-ip=209.85.214.180 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="XLDggVnP" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-22382657540so43026615ad.2 for ; Mon, 03 Mar 2025 12:02:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1741032150; x=1741636950; 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=UFRmuuWC6nLr/d7Z0reZyVHV7p+iTW0U28Cez+/1ICo=; b=XLDggVnPj5uGNc0ydQtxMpg7hn2xHahZklf3anROy+VcyFj+HrwDaYG/wTrvl9K0eb o5NtDtPvrZuwzNxeB36sW5HwDajjqtuAv2EcdVQSBcfjHAI+jLa6U3F6a5pPC1ANFmhN bHxOo3noudZ5IjYYvMuNf5Grm7Uspbo+DkC/c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741032150; x=1741636950; 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=UFRmuuWC6nLr/d7Z0reZyVHV7p+iTW0U28Cez+/1ICo=; b=uTOTOAf65iMhWwZl3EmtBhI8aJQYgX4AubfMUhkwwcbYJkG5jIpOoO2NuMHLuQXhP7 iqGtXhmpl/RgMEEG4sG+E/W0fiaQ6VB4OPlZnSicATaieR81ekB8/Rejztp7ZDy7/bII ygby+ANki5jhA50lHgeSb8Mbc7ubkn7zBqRs4tDCw0nMp7LTR3ntFZKkX4S2fDZZj3Jc RavRbP9PVWhRN3Ve31DDfYS1oSxHdrzvKr+XWHfVI5Yz6oz+hG1dUknWAu7RfrMdxJYc XM2AjFZ7mCJbELsz1pLw1i61JNcDzeDLaVHEm+ycF1zu4gnv+ABaKyzcUxaBDo+UMhqq 5f3g== X-Forwarded-Encrypted: i=1; AJvYcCXrTWWfRUFv5PHvhrhZgNMXhYtiyEaLkVxOPs/Iyl6fW7EPs0n2iJcWc7QZ6THLU5/Lgan3ARY=@vger.kernel.org X-Gm-Message-State: AOJu0YxxMFVxjG6G49x8oaGkb35mYRRKxFFxNuMnSjzjSeNvIrMo0Ioh FmgY9nAgd5kmBMBoKYwZsw1JUcQ4s013y8kfKUORUtDQGhAKduy5kSDLK/72pg== X-Gm-Gg: ASbGncs1kpepUQclpnYRzQUqST1ATugl47KA7Y98oimqWa15PrsVI4TKaSPAyWEJ12p lbfubDkzIAitFXhgZ4eIvVntw22FLuZvWluQdkMvfPQtQ/tSyogIVrySOxTwpIOwxerTh2hg+o5 pwUO4NNbbHV6I38Y9VwU6/iwlrAxBqZDwDRi4eDVlvQx1kaCQt5/Pg97X+rcNeLYPjHJap0x7QM k+5GFkFkyX+aLWGanXTAuuqBkNvM4R3I7CIXKEy4tD9zyNU+GLIMufxe/XcQxeRWdKs0yvwu/xk WxScfHheuUuAVracdoSDXJ6G+HM5scCMHubVBrPhzNNDuSXXT0DYWfgb+EjdpOYlmc3x/QRwJI2 0mtw+0ALTD65WoiUi93BYMEXypQHubIs= X-Google-Smtp-Source: AGHT+IG251vDiS5LnZShDdOM7gPPNx1TJCkqEmU+Hgnl06eBXjvZ6Hm8Vge4jeEDWguBjieJ2hXP5g== X-Received: by 2002:a17:903:32c8:b0:223:245a:11e2 with SMTP id d9443c01a7336-22368f71ed9mr186248885ad.6.1741032150094; Mon, 03 Mar 2025 12:02:30 -0800 (PST) Received: from li-cloudtop.c.googlers.com.com (4.198.125.34.bc.googleusercontent.com. [34.125.198.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223504dc4b4sm81233875ad.171.2025.03.03.12.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 12:02:29 -0800 (PST) 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, omosnace@redhat.com, shuah@kernel.org, arnd@arndb.de, masahiroy@kernel.org, bagasdotme@gmail.com, horms@kernel.org, tweek@google.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, netdev@vger.kernel.org, selinux@vger.kernel.org, hridya@google.com Cc: smoreland@google.com, ynaffit@google.com, kernel-team@android.com Subject: [PATCH v16 2/3] binder: report txn errors via generic netlink Date: Mon, 3 Mar 2025 12:02:11 -0800 Message-ID: <20250303200212.3294679-3-dualli@chromium.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303200212.3294679-1-dualli@chromium.org> References: <20250303200212.3294679-1-dualli@chromium.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Li Li Introduce generic netlink messages into the binder driver so that the Linux/Android system administration processes 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 binder netlink sources and headers are automatically generated from the corresponding binder netlink YAML spec. Don't modify them directly. Signed-off-by: Li Li --- Documentation/admin-guide/binder_netlink.rst | 108 +++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/netlink/specs/binder.yaml | 116 ++++++++++ drivers/android/Kconfig | 1 + drivers/android/Makefile | 2 +- drivers/android/binder.c | 229 ++++++++++++++++++- drivers/android/binder_internal.h | 16 ++ drivers/android/binder_netlink.c | 46 ++++ drivers/android/binder_netlink.h | 23 ++ drivers/android/binder_trace.h | 35 +++ include/uapi/linux/android/binder_netlink.h | 57 +++++ 11 files changed, 630 insertions(+), 4 deletions(-) create mode 100644 Documentation/admin-guide/binder_netlink.rst create mode 100644 Documentation/netlink/specs/binder.yaml create mode 100644 drivers/android/binder_netlink.c create mode 100644 drivers/android/binder_netlink.h create mode 100644 include/uapi/linux/android/binder_netlink.h diff --git a/Documentation/admin-guide/binder_netlink.rst b/Documentation/admin-guide/binder_netlink.rst new file mode 100644 index 000000000000..83f54f0d8c45 --- /dev/null +++ b/Documentation/admin-guide/binder_netlink.rst @@ -0,0 +1,108 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================================================== +Generic Netlink for the Android Binder Driver (Binder Netlink) +============================================================== + +The Generic Netlink subsystem in the Linux kernel provides a generic way for +the Linux kernel to communicate with the user space applications via binder +driver. It is used to report binder transaction errors and warnings to user +space administration process. The driver allows multiple binder devices and +their corresponding binder contexts. Each context and their processes can be +configured independently to report their own transactions. + +Basically, the user space code uses the BINDER_CMD_REPORT_SETUP command to +request what kind of binder transactions should be reported by the driver. +The driver then echoes the attributes in a reply message to acknowledge the +request. The BINDER_CMD_REPORT_SETUP command also registers the current +user space process to receive the reports. This BINDER_CMD_REPORT_SETUP +command is protected by SELinux, to prevent unauthorized user apps from +triggering unexpected reports. + +Currently the driver reports these binder transaction errors and warnings. +1. "FAILED" transactions that fail to reach the target process; +2. "ASYNC_FROZEN" transactions that are delayed due to the target process +being frozen by cgroup freezer; or +3. "SPAM" transactions that are considered spamming according to existing +logic in binder_alloc.c. + +When the specified binder transactions happen, the driver uses the +BINDER_CMD_REPORT command to send a generic netlink message to the +registered process, containing the payload defined in binder.yaml. + +More details about the flags, attributes and operations can be found at the +the doc sections in Documentations/netlink/specs/binder.yaml and the +kernel-doc comments of the new source code in binder.{h|c}. + +Using Binder Netlink +-------------------- + +The Binder Netlink can be used in the same way as any other generic netlink +drivers. Userspace application uses a raw netlink socket to send commands +to and receive packets from the kernel driver. + +Usage example (user space pseudo code): + +:: + /* + * send() below is overloaded to pack netlink commands and attributes + * to nlattr/genlmsghdr/nlmsghdr and then send to the netlink socket. + * + * recv() below is overloaded to receive the raw netlink message from + * the netlink socket, parse nlmsghdr/genlmsghdr to find the netlink + * command and then return the nlattr payload. + */ + + // open netlink socket + int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + + // bind netlink socket + bind(fd, struct socketaddr); + + // get the family id of the binder netlink + send(fd, CTRL_CMD_GETFAMILY, CTRL_ATTR_FAMILY_NAME, + BINDER_FAMILY_NAME); + void *data = recv(CTRL_CMD_NEWFAMILY); + if (!has_nla_type(data, CTRL_ATTR_FAMILY_ID)) { + // Binder Netlink isn't available on this version of Linux kernel + return; + } + __u16 id = nla(data)[CTRL_ATTR_FAMILY_ID]; + __u32 grp = nla(data)[CTRL_ATTR_MCAST_GROUPS][CTRL_ATTR_MCAST_GRP_ID]; + + // join the mcast group to listen to the binder netlink messages + setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &grp, sizeof(grp)); + + // enable per-context binder report + send(fd, id, BINDER_CMD_REPORT_SETUP, "binder", 0, + BINDER_FLAG_FAILED | BINDER_FLAG_DELAYED); + + // confirm the per-context configuration + data = recv(fd, BINDER_CMD_REPLY); + char *context = nla(data)[BINDER_A_CMD_CONTEXT]; + __u32 pid = nla(data)[BINDER_A_CMD_PID]; + __u32 flags = nla(data)[BINDER_A_CMD_FLAGS]; + + // set optional per-process report, overriding the per-context one + send(fd, id, BINDER_CMD_REPORT_SETUP, "binder", getpid(), + BINDER_FLAG_SPAM | BINDER_REPORT_OVERRIDE); + + // confirm the optional per-process configuration + data = recv(fd, BINDER_CMD_REPLY); + context = nla(data)[BINDER_A_CMD_CONTEXT]; + pid = nla(data)[BINDER_A_CMD_PID]; + flags = nla(data)[BINDER_A_CMD_FLAGS]; + + // wait and read all binder reports + while (running) { + data = recv(fd, BINDER_CMD_REPORT); + auto *attr = nla(data)[BINDER_A_REPORT_XXX]; + + // process binder report + do_something(*attr); + } + + // clean up + send(fd, id, BINDER_CMD_REPORT_SETUP, 0, 0); + send(fd, id, BINDER_CMD_REPORT_SETUP, getpid(), 0); + close(fd); diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guide/index.rst index c8af32a8f800..655f39ddf1cf 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -120,6 +120,7 @@ Block-layer and filesystem administration :maxdepth: 1 bcache + binder_netlink binderfs blockdev/index cifs/index diff --git a/Documentation/netlink/specs/binder.yaml b/Documentation/netlink/specs/binder.yaml new file mode 100644 index 000000000000..e184645f6c41 --- /dev/null +++ b/Documentation/netlink/specs/binder.yaml @@ -0,0 +1,116 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) + +name: binder +protocol: genetlink +uapi-header: linux/android/binder_netlink.h +doc: Netlink protocol to report binder transaction errors and warnings. + +definitions: + - + type: flags + name: flag + doc: Define what kind of binder transactions should be reported. + entries: [ failed, async-frozen, spam, override ] + +attribute-sets: + - + name: cmd + doc: The supported attributes of "report-setup" command. + attributes: + - + name: context + type: string + doc: The binder context to enable binder netlink report. + - + name: pid + type: u32 + doc: The binder proc to enable binder netlink report. + - + name: flags + type: u32 + enum: flag + doc: What kind of binder transactions should be reported. + - + name: report + doc: The supported attributes of "report" command + attributes: + - + name: context + type: string + doc: The binder context where the binder netlink report happens. + - + name: err + type: u32 + doc: Copy of binder_driver_return_protocol returned to the sender. + - + name: from_pid + type: u32 + doc: Sender pid of the corresponding binder transaction. + - + name: from_tid + type: u32 + doc: Sender tid of the corresponding binder transaction. + - + name: to_pid + type: u32 + doc: Target pid of the corresponding binder transaction. + - + name: to_tid + type: u32 + doc: Target tid of the corresponding binder transaction. + - + name: reply + type: u32 + doc: 1 means the transaction is a reply, 0 otherwise. + - + name: flags + type: u32 + doc: Copy of binder_transaction_data->flags. + - + name: code + type: u32 + doc: Copy of binder_transaction_data->code. + - + name: data_size + type: u32 + doc: Copy of binder_transaction_data->data_size. + +operations: + list: + - + name: report-setup + doc: Set flags from user space. + attribute-set: cmd + + do: + request: ¶ms + attributes: + - context + - pid + - flags + reply: *params + - + name: report + doc: Send the requested reports to user space. + attribute-set: report + + event: + attributes: + - context + - err + - from_pid + - from_tid + - to_pid + - to_tid + - reply + - flags + - code + - data_size + +kernel-family: + headers: [ "binder_internal.h" ] + +mcast-groups: + list: + - + name: report 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..b8874dba884e 100644 --- a/drivers/android/Makefile +++ b/drivers/android/Makefile @@ -2,5 +2,5 @@ ccflags-y += -I$(src) # needed for trace events obj-$(CONFIG_ANDROID_BINDERFS) += binderfs.o -obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o binder_alloc.o +obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o binder_alloc.o binder_netlink.o obj-$(CONFIG_ANDROID_BINDER_IPC_SELFTEST) += binder_alloc_selftest.o diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 76052006bd87..262c120a175a 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -72,6 +72,7 @@ #include +#include "binder_netlink.h" #include "binder_internal.h" #include "binder_trace.h" @@ -2990,6 +2991,110 @@ static void binder_set_txn_from_error(struct binder_transaction *t, int id, binder_thread_dec_tmpref(from); } +/** + * binder_find_proc() - find the binder_proc by pid + * @pid: the target process + * + * Returns the struct binder_proc if the pid is found, or NULL otherwise. + */ +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 == pid) + break; + } + mutex_unlock(&binder_procs_lock); + + return proc; +} + +/** + * binder_netlink_enabled() - check if binder netlink reports are enabled + * @proc: the binder_proc to check + * @mask: the categories of binder netlink reports + * + * Returns true if certain binder netlink reports are enabled for this binder + * proc (when per-process overriding takes effect) or context. + */ +static bool binder_netlink_enabled(struct binder_proc *proc, u32 mask) +{ + struct binder_context *context = proc->context; + + if (!genl_has_listeners(&binder_nl_family, &init_net, BINDER_NLGRP_REPORT)) + return false; + + if (proc->report_flags & BINDER_FLAG_OVERRIDE) + return (proc->report_flags & mask) != 0; + else + return (context->report_flags & mask) != 0; +} + +/** + * binder_netlink_report() - report one binder netlink event + * @context: the binder context + * @err: copy of binder_driver_return_protocol returned to the sender + * @pid: sender process + * @tid: sender thread + * @to_pid: target process + * @to_tid: target thread + * @reply: whether the binder transaction is a reply + * @tr: the binder transaction data + * + * Packs the report data into a binder netlink message and send it. + */ +static void binder_netlink_report(struct binder_context *context, u32 err, + u32 pid, u32 tid, u32 to_pid, u32 to_tid, + u32 reply, + struct binder_transaction_data *tr) +{ + struct sk_buff *skb; + void *hdr; + int ret; + + trace_binder_netlink_report(context->name, err, pid, tid, to_pid, + to_tid, reply, tr); + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) { + pr_err("Failed to alloc binder netlink message\n"); + return; + } + + hdr = genlmsg_put(skb, 0, atomic_inc_return(&context->report_seq), + &binder_nl_family, 0, BINDER_CMD_REPORT); + if (!hdr) + goto free_skb; + + if (nla_put_string(skb, BINDER_A_REPORT_CONTEXT, context->name) || + nla_put_u32(skb, BINDER_A_REPORT_ERR, err) || + nla_put_u32(skb, BINDER_A_REPORT_FROM_PID, pid) || + nla_put_u32(skb, BINDER_A_REPORT_FROM_TID, tid) || + nla_put_u32(skb, BINDER_A_REPORT_TO_PID, to_pid) || + nla_put_u32(skb, BINDER_A_REPORT_TO_TID, to_tid) || + nla_put_u32(skb, BINDER_A_REPORT_REPLY, reply) || + nla_put_u32(skb, BINDER_A_REPORT_FLAGS, tr->flags) || + nla_put_u32(skb, BINDER_A_REPORT_CODE, tr->code) || + nla_put_u32(skb, BINDER_A_REPORT_DATA_SIZE, tr->data_size)) + goto cancel_skb; + + genlmsg_end(skb, hdr); + + ret = genlmsg_multicast(&binder_nl_family, skb, 0, BINDER_NLGRP_REPORT, GFP_KERNEL); + if (ret < 0) + pr_err("Failed to send binder netlink message: %d\n", ret); + return; + +cancel_skb: + pr_err("Failed to add attributes to binder netlink message\n"); + genlmsg_cancel(skb, hdr); +free_skb: + pr_err("Free binder netlink report message on error\n"); + nlmsg_free(skb); +} + static void binder_transaction(struct binder_proc *proc, struct binder_thread *thread, struct binder_transaction_data *tr, int reply, @@ -3683,10 +3788,17 @@ static void binder_transaction(struct binder_proc *proc, return_error_line = __LINE__; goto err_copy_data_failed; } - if (t->buffer->oneway_spam_suspect) + if (t->buffer->oneway_spam_suspect) { tcomplete->type = BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT; - else + if (binder_netlink_enabled(proc, BINDER_FLAG_SPAM)) + binder_netlink_report(context, BR_ONEWAY_SPAM_SUSPECT, + proc->pid, thread->pid, + target_proc ? target_proc->pid : 0, + target_thread ? target_thread->pid : 0, + reply, tr); + } else { tcomplete->type = BINDER_WORK_TRANSACTION_COMPLETE; + } t->work.type = BINDER_WORK_TRANSACTION; if (reply) { @@ -3736,8 +3848,15 @@ static void binder_transaction(struct binder_proc *proc, * process and is put in a pending queue, waiting for the target * process to be unfrozen. */ - if (return_error == BR_TRANSACTION_PENDING_FROZEN) + if (return_error == BR_TRANSACTION_PENDING_FROZEN) { tcomplete->type = BINDER_WORK_TRANSACTION_PENDING; + if (binder_netlink_enabled(proc, BINDER_FLAG_ASYNC_FROZEN)) + binder_netlink_report(context, return_error, + proc->pid, thread->pid, + target_proc ? target_proc->pid : 0, + target_thread ? target_thread->pid : 0, + reply, tr); + } binder_enqueue_thread_work(thread, tcomplete); if (return_error && return_error != BR_TRANSACTION_PENDING_FROZEN) @@ -3799,6 +3918,13 @@ static void binder_transaction(struct binder_proc *proc, binder_dec_node_tmpref(target_node); } + if (binder_netlink_enabled(proc, BINDER_FLAG_FAILED)) + binder_netlink_report(context, return_error, + proc->pid, thread->pid, + target_proc ? target_proc->pid : 0, + target_thread ? target_thread->pid : 0, + reply, tr); + binder_debug(BINDER_DEBUG_FAILED_TRANSACTION, "%d:%d transaction %s to %d:%d failed %d/%d/%d, code %u size %lld-%lld line %d\n", proc->pid, thread->pid, reply ? "reply" : @@ -6334,6 +6460,98 @@ binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer) mutex_unlock(&binder_deferred_lock); } +/** + * binder_nl_report_setup_doit() - netlink .doit handler + * @skb: the metadata struct passed from netlink driver + * @info: the generic netlink struct passed from netlink driver + * + * Implements the .doit function to process binder netlink commands. + */ +int binder_nl_report_setup_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct binder_context *context = NULL; + struct binder_device *device; + struct binder_proc *proc; + u32 flags, pid; + void *hdr; + int ret; + + ret = security_binder_setup_report(current_cred()); + if (ret < 0) { + NL_SET_ERR_MSG(info->extack, "Permission denied"); + return ret; + } + + hlist_for_each_entry(device, &binder_devices, hlist) { + if (!nla_strcmp(info->attrs[BINDER_A_CMD_CONTEXT], + device->context.name)) { + context = &device->context; + break; + } + } + + if (!context) { + NL_SET_ERR_MSG(info->extack, "Unknown binder context"); + return -EINVAL; + } + + pid = nla_get_u32(info->attrs[BINDER_A_CMD_PID]); + flags = nla_get_u32(info->attrs[BINDER_A_CMD_FLAGS]); + + if (!pid) { + /* Set the global flags for the whole binder context */ + context->report_flags = flags; + } else { + /* Set the per-process flags */ + proc = binder_find_proc(pid); + if (!proc) { + NL_SET_ERR_MSG_FMT(info->extack, + "Invalid binder report pid %u", + pid); + ret = -EINVAL; + goto err_exit; + } + + proc->report_flags = flags; + } + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) { + pr_err("Failed to alloc binder netlink reply message\n"); + ret = -ENOMEM; + goto err_exit; + } + + hdr = genlmsg_iput(skb, info); + if (!hdr) + goto free_skb; + + if (nla_put_string(skb, BINDER_A_CMD_CONTEXT, context->name) || + nla_put_u32(skb, BINDER_A_CMD_PID, pid) || + nla_put_u32(skb, BINDER_A_CMD_FLAGS, flags)) + goto cancel_skb; + + genlmsg_end(skb, hdr); + + if (genlmsg_reply(skb, info)) { + pr_err("Failed to send binder netlink reply message\n"); + ret = -EFAULT; + goto err_exit; + } + + return 0; + +cancel_skb: + pr_err("Failed to add reply attributes to binder netlink message\n"); + genlmsg_cancel(skb, hdr); +free_skb: + pr_err("Free binder netlink reply message on error\n"); + nlmsg_free(skb); + ret = -EMSGSIZE; +err_exit: + return ret; +} + static void print_binder_transaction_ilocked(struct seq_file *m, struct binder_proc *proc, const char *prefix, @@ -7013,6 +7231,11 @@ static int __init binder_init(void) if (ret) goto err_init_binder_device_failed; + ret = genl_register_family(&binder_nl_family); + if (ret) { + pr_err("Failed to register binder netlink family\n"); + goto err_init_binder_device_failed; + } return ret; err_init_binder_device_failed: diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h index 6a66c9769c6c..8ddd1ddea8e0 100644 --- a/drivers/android/binder_internal.h +++ b/drivers/android/binder_internal.h @@ -11,15 +11,28 @@ #include #include #include +#include #include #include "binder_alloc.h" #include "dbitmap.h" +/** + * 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 + * @report_flags: the categories of binder transactions that would + * 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; + u32 report_flags; + atomic_t report_seq; }; /** @@ -413,6 +426,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_genl_flag). * * Bookkeeping structure for binder processes */ @@ -451,6 +466,7 @@ struct binder_proc { spinlock_t outer_lock; struct dentry *binderfs_entry; bool oneway_spam_detection_enabled; + u32 report_flags; }; /** diff --git a/drivers/android/binder_netlink.c b/drivers/android/binder_netlink.c new file mode 100644 index 000000000000..9dc1820951c3 --- /dev/null +++ b/drivers/android/binder_netlink.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder.yaml */ +/* YNL-GEN kernel source */ + +#include +#include + +#include "binder_netlink.h" + +#include +#include + +/* BINDER_CMD_REPORT_SETUP - do */ +static const struct nla_policy binder_report_setup_nl_policy[BINDER_A_CMD_FLAGS + 1] = { + [BINDER_A_CMD_CONTEXT] = { .type = NLA_NUL_STRING, }, + [BINDER_A_CMD_PID] = { .type = NLA_U32, }, + [BINDER_A_CMD_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0xf), +}; + +/* Ops table for binder */ +static const struct genl_split_ops binder_nl_ops[] = { + { + .cmd = BINDER_CMD_REPORT_SETUP, + .doit = binder_nl_report_setup_doit, + .policy = binder_report_setup_nl_policy, + .maxattr = BINDER_A_CMD_FLAGS, + .flags = GENL_CMD_CAP_DO, + }, +}; + +static const struct genl_multicast_group binder_nl_mcgrps[] = { + [BINDER_NLGRP_REPORT] = { "report", }, +}; + +struct genl_family binder_nl_family __ro_after_init = { + .name = BINDER_FAMILY_NAME, + .version = BINDER_FAMILY_VERSION, + .netnsok = true, + .parallel_ops = true, + .module = THIS_MODULE, + .split_ops = binder_nl_ops, + .n_split_ops = ARRAY_SIZE(binder_nl_ops), + .mcgrps = binder_nl_mcgrps, + .n_mcgrps = ARRAY_SIZE(binder_nl_mcgrps), +}; diff --git a/drivers/android/binder_netlink.h b/drivers/android/binder_netlink.h new file mode 100644 index 000000000000..0ef8c91ab319 --- /dev/null +++ b/drivers/android/binder_netlink.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_BINDER_GEN_H +#define _LINUX_BINDER_GEN_H + +#include +#include + +#include +#include + +int binder_nl_report_setup_doit(struct sk_buff *skb, struct genl_info *info); + +enum { + BINDER_NLGRP_REPORT, +}; + +extern struct genl_family binder_nl_family; + +#endif /* _LINUX_BINDER_GEN_H */ diff --git a/drivers/android/binder_trace.h b/drivers/android/binder_trace.h index 16de1b9e72f7..6fb454bcd857 100644 --- a/drivers/android/binder_trace.h +++ b/drivers/android/binder_trace.h @@ -423,6 +423,41 @@ TRACE_EVENT(binder_return, "unknown") ); +TRACE_EVENT(binder_netlink_report, + TP_PROTO(const char *name, u32 err, u32 pid, u32 tid, u32 to_pid, + u32 to_tid, u32 reply, struct binder_transaction_data *tr), + TP_ARGS(name, err, pid, tid, to_pid, to_tid, reply, tr), + TP_STRUCT__entry( + __field(const char *, name) + __field(u32, err) + __field(u32, pid) + __field(u32, tid) + __field(u32, to_pid) + __field(u32, to_tid) + __field(u32, reply) + __field(u32, flags) + __field(u32, code) + __field(binder_size_t, data_size) + ), + TP_fast_assign( + __entry->name = name; + __entry->err = err; + __entry->pid = pid; + __entry->tid = tid; + __entry->to_pid = to_pid; + __entry->to_tid = to_tid; + __entry->reply = reply; + __entry->flags = tr->flags; + __entry->code = tr->code; + __entry->data_size = tr->data_size; + ), + TP_printk("%s: %d %d:%d -> %d:%d %s flags=0x08%x code=%d %llu", + __entry->name, __entry->err, __entry->pid, __entry->tid, + __entry->to_pid, __entry->to_tid, + __entry->reply ? "reply" : "", + __entry->flags, __entry->code, __entry->data_size) +); + #endif /* _BINDER_TRACE_H */ #undef TRACE_INCLUDE_PATH diff --git a/include/uapi/linux/android/binder_netlink.h b/include/uapi/linux/android/binder_netlink.h new file mode 100644 index 000000000000..fa926ed19507 --- /dev/null +++ b/include/uapi/linux/android/binder_netlink.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_ANDROID_BINDER_NETLINK_H +#define _UAPI_LINUX_ANDROID_BINDER_NETLINK_H + +#define BINDER_FAMILY_NAME "binder" +#define BINDER_FAMILY_VERSION 1 + +/* + * Define what kind of binder transactions should be reported. + */ +enum binder_flag { + BINDER_FLAG_FAILED = 1, + BINDER_FLAG_ASYNC_FROZEN = 2, + BINDER_FLAG_SPAM = 4, + BINDER_FLAG_OVERRIDE = 8, +}; + +enum { + BINDER_A_CMD_CONTEXT = 1, + BINDER_A_CMD_PID, + BINDER_A_CMD_FLAGS, + + __BINDER_A_CMD_MAX, + BINDER_A_CMD_MAX = (__BINDER_A_CMD_MAX - 1) +}; + +enum { + BINDER_A_REPORT_CONTEXT = 1, + BINDER_A_REPORT_ERR, + BINDER_A_REPORT_FROM_PID, + BINDER_A_REPORT_FROM_TID, + BINDER_A_REPORT_TO_PID, + BINDER_A_REPORT_TO_TID, + BINDER_A_REPORT_REPLY, + BINDER_A_REPORT_FLAGS, + BINDER_A_REPORT_CODE, + BINDER_A_REPORT_DATA_SIZE, + + __BINDER_A_REPORT_MAX, + BINDER_A_REPORT_MAX = (__BINDER_A_REPORT_MAX - 1) +}; + +enum { + BINDER_CMD_REPORT_SETUP = 1, + BINDER_CMD_REPORT, + + __BINDER_CMD_MAX, + BINDER_CMD_MAX = (__BINDER_CMD_MAX - 1) +}; + +#define BINDER_MCGRP_REPORT "report" + +#endif /* _UAPI_LINUX_ANDROID_BINDER_NETLINK_H */ From patchwork Mon Mar 3 20:02:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Li X-Patchwork-Id: 13999393 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 2EB5C2376EC for ; Mon, 3 Mar 2025 20:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741032154; cv=none; b=RFcUjfQmDCLuU/kv91jlwcFV8E3xvBLuQcvfQ0QcuncaAGc4XiGPVZfhKCKujlnzWrO6Ue3RKQA52qA7jSbNcoiTs8tdxlBMf7IdtJSZ5BBMOt/C5mOGZSMAzNNNMPBFfgxi2Yq9T8hn4AZ2Qb7TBj4ufp32sZf6uci3QIJl+yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741032154; c=relaxed/simple; bh=VFQeuhQrmXgZOY+JfXBPbjeF37rWPb4GdeTObDb2Rf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QlN9hc+iMsChXO7tgyZzy2xJr3V6IuQfXMSlTq2Y/DnWVoX4Iv0Mwo0/KaH0/D51VHRCPTnn5FJcWU7E+ks8O6hVrYSz/sutpXoUTuGXsMeqcqtImXCx8800Wg+d8GZVozok6csmcKyTdgRcULimMSOg8lZOrSGTn3Brdb8b0zk= 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=RRFK5+IW; arc=none smtp.client-ip=209.85.214.180 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="RRFK5+IW" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2238d965199so35667575ad.2 for ; Mon, 03 Mar 2025 12:02:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1741032152; x=1741636952; 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=Bqs6enPVx21oxb5GivnZU1DWbwEExp/3gOjrVfmP78c=; b=RRFK5+IWJQs3c2TMeNytKYerVfuXWNDsh/vWTzYJFLyt5xnIaTtm9JinCt1oMOMKpY LdvKYI+FXd2jgoq9fGh0x06Jgre6UYIS2yUiep0+mMa1+V3bkeq9CNo4qEghokE2hK2D N7r4Ctpe2UhwMS/kNzfVlJcqsKs1X8aOa13uo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741032152; x=1741636952; 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=Bqs6enPVx21oxb5GivnZU1DWbwEExp/3gOjrVfmP78c=; b=uYzkV3PwBveAbJ5eZjTggLUEpbU1NlKlpxQXZ+WO0L3fJh044NXY4e8QwufSYNoNzG i2I3RsojSSkdcndqPOT64+4GAzccfnYKZuCVZ+jFT2O+OOxpoAPJ5Qxob3l6YIF20pP/ 4L1LHSxCcIaAJp+YrUq4xRPUxrfkYDmy36VExlAegpuuJCk5HIw0Kvtq9/8LrLKXfPvu pcdbSOHJKLYC8k0+Q9m7+VUp+MTkNDW1en3vSkoCWryFEncW/gNAgUJal+lXR4IyXPTr 17Eeul+9IPrfWiU9VzQkpClXvO4kV7XK6QY+EWIQz1uUxE82649xEbr3Z1Gb1GKOa6IP QmPQ== X-Forwarded-Encrypted: i=1; AJvYcCVxrHmTkMzhF0x1vgKFTi7lEtCn0uVC9v6wXRESX9zhXDjZ2oCdxUZRIlhCLDf1K5bvWiZ3HV4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8YR0XqljJCPkrHLF8+sZv6mMzbNKiFb1RDFlFigBFh13rM7b6 wEHdP/sg4TckDC3xBaPJfnm0D7dqPhmGMqcfhgsiNfQhgCkgaaNKC3ibcWF15A== X-Gm-Gg: ASbGncsJNvZgz66qAzqGUPSeloaeCYuHu2r6gep02ckG+r74M/3gcWsHgSQEiTQrbYv TKBV7BSus6NDh6KsNOgGpX3LsWXeynm5Y7UhIE06PMgQxKnFe29CDKZokOYl8Dyp8/UbX/DmJBC IywfMqTB2IFrPINzlnhCBdnWvubmkVp1XfsJwqSE05ngjssCPFL+mYnprq3ClloSeEDtqZF/Q1G UymsRV8NY9z/d4cfmedeUluHTX/vxrh+vd0T/OM9PJH5yNPFA+xdVeVkbHhL/OYNYvuXYneGbqH rVri8t6jzkUf2kjBhZtafbby/5SxBSetHaogi0d8H+oFIRsIDXG3QmYh8XQD43feiWe2NTt5ZEc RC28mU/aL73LlEZL9qJpnG2mUWf5tjHE= X-Google-Smtp-Source: AGHT+IHEpC0wzYC9qpTOKYzyBCFKX1RplbM8mEpi5mu7LaJ5QXKsMTUayHNtXumG2Q6HyHXT6kFqmQ== X-Received: by 2002:a17:903:198e:b0:21f:988d:5758 with SMTP id d9443c01a7336-2236924e748mr224147945ad.35.1741032152431; Mon, 03 Mar 2025 12:02:32 -0800 (PST) Received: from li-cloudtop.c.googlers.com.com (4.198.125.34.bc.googleusercontent.com. [34.125.198.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223504dc4b4sm81233875ad.171.2025.03.03.12.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 12:02:31 -0800 (PST) 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, omosnace@redhat.com, shuah@kernel.org, arnd@arndb.de, masahiroy@kernel.org, bagasdotme@gmail.com, horms@kernel.org, tweek@google.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, netdev@vger.kernel.org, selinux@vger.kernel.org, hridya@google.com Cc: smoreland@google.com, ynaffit@google.com, kernel-team@android.com Subject: [PATCH v16 3/3] binder: generic netlink binder_features flag Date: Mon, 3 Mar 2025 12:02:12 -0800 Message-ID: <20250303200212.3294679-4-dualli@chromium.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303200212.3294679-1-dualli@chromium.org> References: <20250303200212.3294679-1-dualli@chromium.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Li Li Add a flag to binder_features to indicate that the generic netlink feature is available. Signed-off-by: Li Li --- drivers/android/binderfs.c | 8 ++++++++ .../selftests/filesystems/binderfs/binderfs_test.c | 1 + 2 files changed, 9 insertions(+) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 94c6446604fc..b3d21ccd81f2 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -59,6 +59,7 @@ struct binder_features { bool oneway_spam_detection; bool extended_error; bool freeze_notification; + bool generic_netlink; }; static const struct constant_table binderfs_param_stats[] = { @@ -76,6 +77,7 @@ static struct binder_features binder_features = { .oneway_spam_detection = true, .extended_error = true, .freeze_notification = true, + .generic_netlink = true, }; static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb) @@ -619,6 +621,12 @@ static int init_binder_features(struct super_block *sb) if (IS_ERR(dentry)) return PTR_ERR(dentry); + dentry = binderfs_create_file(dir, "generic_netlink", + &binder_features_fops, + &binder_features.generic_netlink); + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + return 0; } diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c index 81db85a5cc16..96e64ebf910f 100644 --- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c +++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c @@ -65,6 +65,7 @@ static int __do_binderfs_test(struct __test_metadata *_metadata) "oneway_spam_detection", "extended_error", "freeze_notification", + "generic_netlink", }; change_mountns(_metadata);