{"id":7054,"date":"2022-12-20T19:34:47","date_gmt":"2022-12-20T22:34:47","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/avc_has_perm-man3\/"},"modified":"2022-12-20T19:34:47","modified_gmt":"2022-12-20T22:34:47","slug":"avc_has_perm-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/avc_has_perm-man3\/","title":{"rendered":"avc_has_perm (man3)"},"content":{"rendered":"<h1 align=\"center\">avc_has_perm<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#ENTRY REFERENCES\">ENTRY REFERENCES<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \u2212 obtain and audit SELinux access decisions<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <selinux\/selinux.h> <br \/> #include <selinux\/avc.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>void avc_entry_ref_init(struct avc_entry_ref *<\/b><i>aeref<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int avc_has_perm(security_id_t<\/b> <i>ssid<\/i><b>, security_id_t<\/b> <i>tsid<\/i><b>,<\/b><\/p>\n<p style=\"margin-left:37%;\"><b>security_class_t<\/b> <i>tclass<\/i><b>, access_vector_t<\/b> <i>requested<\/i><b>, <br \/> struct avc_entry_ref *<\/b><i>aeref<\/i><b>, void *<\/b><i>auditdata<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int avc_has_perm_noaudit(security_id_t<\/b> <i>ssid<\/i><b>, security_id_t<\/b> <i>tsid<\/i><b>,<\/b><\/p>\n<p style=\"margin-left:37%;\"><b>security_class_t<\/b> <i>tclass<\/i><b>, access_vector_t<\/b> <i>requested<\/i><b>, <br \/> struct avc_entry_ref *<\/b><i>aeref<\/i><b>, struct av_decision *<\/b><i>avd<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>void avc_audit(security_id_t<\/b> <i>ssid<\/i><b>, security_id_t<\/b> <i>tsid<\/i><b>,<\/b><\/p>\n<p style=\"margin-left:34%;\"><b>security_class_t<\/b> <i>tclass<\/i><b>, access_vector_t<\/b> <i>requested<\/i><b>, <br \/> struct av_decision *<\/b><i>avd<\/i><b>, int<\/b> <i>result<\/i><b>, void *<\/b><i>auditdata<\/i><b>);<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Direct use of these functions is generally discouraged in favor of the higher level interface <b>selinux_check_access(3)<\/b> since the latter automatically handles the dynamic mapping of class and permission names to their policy values and proper handling of allow_unknown.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When using any of the functions that take policy integer values for classes or permissions as inputs, use <b>string_to_security_class(3)<\/b> and <b>string_to_av_perm(3)<\/b> to map the class and permission names to their policy values. These values may change across a policy reload, so they should be re-acquired on every use or using a <b>SELINUX_CB_POLICYLOAD<\/b> callback set via <b>selinux_set_callback(3).<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">An alternative approach is to use <b>selinux_set_mapping(3)<\/b> to create a mapping from class and permission index values used by the application to the policy values, thereby allowing the application to pass its own fixed constants for the classes and permissions to these functions and internally mapping them on demand. However, this also requires setting up a callback as above to address policy reloads.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>avc_entry_ref_init<\/b>() initializes an <b>avc_entry_ref<\/b> structure; see <b>ENTRY REFERENCES<\/b> below. This function may be implemented as a macro.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>avc_has_perm<\/b>() checks whether the <i>requested<\/i> permissions are granted for subject SID <i>ssid<\/i> and target SID <i>tsid<\/i>, interpreting the permissions based on <i>tclass<\/i> and updating <i>aeref<\/i>, if non-NULL, to refer to a cache entry with the resulting decision. The granting or denial of permissions is audited in accordance with the policy. The <i>auditdata<\/i> parameter is for supplemental auditing; see <b>avc_audit<\/b>() below.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>avc_has_perm_noaudit<\/b>() behaves as <b>avc_has_perm<\/b>() without producing an audit message. The access decision is returned in <i>avd<\/i> and can be passed to <b>avc_audit<\/b>() explicitly.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>avc_audit<\/b>() produces an audit message for the access query represented by <i>ssid<\/i>, <i>tsid<\/i>, <i>tclass<\/i>, and <i>requested<\/i>, with a decision represented by <i>avd<\/i>. Pass the value returned by <b>avc_has_perm_noaudit<\/b>() as <i>result<\/i>. The <i>auditdata<\/i> parameter is passed to the user-supplied <b>func_audit<\/b> callback and can be used to add supplemental information to the audit message; see <b>avc_init<\/b>(3).<\/p>\n<h2>ENTRY REFERENCES <a name=\"ENTRY REFERENCES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Entry references can be used to speed cache performance for repeated queries on the same subject and target. The userspace AVC will check the <i>aeref<\/i> argument, if supplied, before searching the cache on a permission query. After a query is performed, <i>aeref<\/i> will be updated to reference the cache entry for that query. A subsequent query on the same subject and target will then have the decision at hand without having to walk the cache.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">After declaring an <b>avc_entry_ref<\/b> structure, use <b>avc_entry_ref_init<\/b>() to initialize it before passing it to <b>avc_has_perm<\/b>() or <b>avc_has_perm_noaudit<\/b>() for the first time. Using an uninitialized structure will produce undefined behavior.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">If requested permissions are granted, zero is returned. If requested permissions are denied or an error occurred, \u22121 is returned and <i>errno<\/i> is set appropriately.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In permissive mode, zero will be returned and <i>errno<\/i> unchanged even if permissions were denied. <b>avc_has_perm<\/b>() will still produce an audit message in this case.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p style=\"margin-top: 1em\"><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">A requested permission was denied.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The <i>tclass<\/i> and\/or the security contexts referenced by <i>ssid<\/i> and <i>tsid<\/i> are not recognized by the currently loaded policy.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOMEM<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>An attempt to allocate memory failed.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Internal errors encountered by the userspace AVC may cause certain values of <i>errno<\/i> to be returned unexpectedly. For example, netlink socket errors may produce <b>EACCES<\/b> or <b>EINVAL<\/b>. Make sure that userspace object managers are granted appropriate access to netlink by the policy.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Originally Eamon Walsh. Updated by Stephen Smalley <sds@tycho.nsa.gov><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>selinux_check_access(3), string_to_security_class(3), string_to_av_perm(3), selinux_set_callback(3), selinux_set_mapping(3), avc_init<\/b>(3), <b>avc_context_to_sid<\/b>(3), <b>avc_cache_stats<\/b>(3), <b>avc_add_callback<\/b>(3), <b>security_compute_av<\/b>(3), <b>selinux<\/b>(8)<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \u2212 obtain and audit SELinux access decisions <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,3401,3007],"class_list":["post-7054","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-avc_has_perm","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7054"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7054\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}