From nobody Wed Aug 17 14:23:50 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M79HW0tkmz4ZZWw; Wed, 17 Aug 2022 14:23:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M79HW0QF4z3PSK; Wed, 17 Aug 2022 14:23:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660746231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=E5bjSPV/tqCVTud6rQ6v40cBi/pEOO6GWjKglUCOQ7k=; b=It2OlLUgjGL21ay9KkyN2x3OlyQP7+1vH7etNV8cMajIJDGCymFZ2DUtYWSmUxqMNVqeNw 3OClO/CDd1ap6oHcfP8IJVizZJrrN0B0cveVoqEhLMNDfQOr/2xufTzpdkau36f75NRYqz 2MHn4kGGwX1tiM1B1VBW9jUgd/IlReCcHl1tJCni5QDuH3h1/evKkMeuXwGp8GrEfH11k8 PV1RHEMHP6Gobytf1VuiRqwAdAoXB3Fd5ffEr9eFF+aUzTvcI0HiMHMZ0ZUvsKTSKP8mrJ xO7OsVt3g2d/yAhq/ggFVqwkyZ1jyXhzi1J/dn2YdoMi9a2vmALfPwdxEpVenA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M79HV6KBlzsQB; Wed, 17 Aug 2022 14:23:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27HENoh3024600; Wed, 17 Aug 2022 14:23:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27HENoR2024599; Wed, 17 Aug 2022 14:23:50 GMT (envelope-from git) Date: Wed, 17 Aug 2022 14:23:50 GMT Message-Id: <202208171423.27HENoR2024599@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 60dae3b83bec - main - mac: cheaper check for mac_pipe_check_read List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 60dae3b83bec5b8fa42c18bd1caaa8b4075167ca Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660746231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=E5bjSPV/tqCVTud6rQ6v40cBi/pEOO6GWjKglUCOQ7k=; b=bMRUm1s8DRrQnMXDo6Feu7E5tPDtepGfWOP/tKqQwA7I4USoy8kBpgSS114+lcu+x7A7SF KhdxfxG/blok6jzilhO3G92ByxdQVLrjO4dBj5xZuiTp2UlcbK2r86HQh6Xdc6T5nwg38Z nZfi4ooCcqVofW9mbU5r1sTR7kflNwZGq/6ITVtngQAS101QGOqTL0nx8NNc0uNJTscvVT cuF46brcGLb4jrVhC4ODfA+Mvs5vRGlIcTxmaM+vfPpTpsApXHRVHTvWpv3eRs+euYCvgY AwSKgnr/f0V7ltj+Cyo5dlJ4AO5B3rUJligR18Z5/4isS4yHnfoQs+/5OS1vCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660746231; a=rsa-sha256; cv=none; b=o+aB4tD+F2jJOxzLemuZE3D61YMCWW9QQ+8XrMFm9VKTHQPVZAVJv4Dcj50OJ4Qawyzzjy CJ5Ard0iWkjpYI7mmWUsi9LhFo3F0NnIz8R1zTf+FSEL9NZu8ZTe5x9s2HA+9Yv/AruruW ETwMKt0Lh+T90sMm70/fBjoswo6gYxo2ls41SrIVP8RuiEGzavojhr2CCQxMUubWIL9MVt Ti3hSwulILtfY+oFXu+I+ll3b6G/i6ttBk9/Hr1lYqdlPJ54s5cMSoDyPSqi41DFtMlhnL 6OEa852N9jnWUve5dDZcujETJJ7D1R7qofj4rXF8+h7xzQzfFDkg9pwQAWPfkg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=60dae3b83bec5b8fa42c18bd1caaa8b4075167ca commit 60dae3b83bec5b8fa42c18bd1caaa8b4075167ca Author: Mateusz Guzik AuthorDate: 2022-08-08 19:14:09 +0000 Commit: Mateusz Guzik CommitDate: 2022-08-17 14:21:25 +0000 mac: cheaper check for mac_pipe_check_read Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D36082 --- sys/security/mac/mac_framework.c | 3 +++ sys/security/mac/mac_framework.h | 17 ++++++++++++++++- sys/security/mac/mac_pipe.c | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sys/security/mac/mac_framework.c b/sys/security/mac/mac_framework.c index e773a3840464..8fc67f6c1b85 100644 --- a/sys/security/mac/mac_framework.c +++ b/sys/security/mac/mac_framework.c @@ -145,6 +145,7 @@ FPFLAG_RARE(vnode_check_access); FPFLAG_RARE(vnode_check_readlink); FPFLAG_RARE(pipe_check_stat); FPFLAG_RARE(pipe_check_poll); +FPFLAG_RARE(pipe_check_read); FPFLAG_RARE(ifnet_create_mbuf); FPFLAG_RARE(ifnet_check_transmit); @@ -447,6 +448,8 @@ struct mac_policy_fastpath_elem mac_policy_fastpath_array[] = { .flag = &mac_pipe_check_stat_fp_flag }, { .offset = FPO(pipe_check_poll), .flag = &mac_pipe_check_poll_fp_flag }, + { .offset = FPO(pipe_check_read), + .flag = &mac_pipe_check_read_fp_flag }, { .offset = FPO(ifnet_create_mbuf), .flag = &mac_ifnet_create_mbuf_fp_flag }, { .offset = FPO(ifnet_check_transmit), diff --git a/sys/security/mac/mac_framework.h b/sys/security/mac/mac_framework.h index 51dbcf909cc4..31951c97a69e 100644 --- a/sys/security/mac/mac_framework.h +++ b/sys/security/mac/mac_framework.h @@ -271,7 +271,22 @@ extern bool mac_pipe_check_stat_fp_flag; #endif #define mac_pipe_check_stat_enabled() __predict_false(mac_pipe_check_stat_fp_flag) int mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp); -int mac_pipe_check_read(struct ucred *cred, struct pipepair *pp); +int mac_pipe_check_read_impl(struct ucred *cred, struct pipepair *pp); +#ifdef MAC +extern bool mac_pipe_check_read_fp_flag; +#else +#define mac_pipe_check_read_fp_flag false +#endif +#define mac_pipe_check_read_enabled() __predict_false(mac_pipe_check_read_fp_flag) +static inline int +mac_pipe_check_read(struct ucred *cred, struct pipepair *pp) +{ + + if (mac_pipe_check_read_enabled()) + return (mac_pipe_check_read_impl(cred, pp)); + return (0); +} + int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp); void mac_pipe_create(struct ucred *cred, struct pipepair *pp); void mac_pipe_destroy(struct pipepair *); diff --git a/sys/security/mac/mac_pipe.c b/sys/security/mac/mac_pipe.c index 799801905d54..e58bcd9166e1 100644 --- a/sys/security/mac/mac_pipe.c +++ b/sys/security/mac/mac_pipe.c @@ -179,7 +179,7 @@ MAC_CHECK_PROBE_DEFINE2(pipe_check_read, "struct ucred *", "struct pipepair *"); int -mac_pipe_check_read(struct ucred *cred, struct pipepair *pp) +mac_pipe_check_read_impl(struct ucred *cred, struct pipepair *pp) { int error;