Annotate Deprecated Functions in libselinux
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.
External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared here
int foo(void) {
^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {
The annoying part is internal users of the routines. We could always make a v2 version of the function for internal callers, and leave the old interfaces intact to work around the warnings, or just pragma them out. This series pragma's them out.
diagnostic push has been supported since GCC v4.6. Earlier versions will warn on this, and the sideffect is that the diagnostic ignored pragma will be valid for the rest of the file. Clang has similair support thats been around *at least* since clang 6.0.
[PATCH 01/17] security_load_booleans: update return comment [PATCH 02/17] selinux_booleans_path: annotate deprecated [PATCH 03/17] selinux_booleans_path: annotate deprecated [PATCH 04/17] selinux_users_path: annotate deprecated [PATCH 05/17] rpm_execcon: annotate deprecated
[PATCH 06/17] sidget: annotate deprecated
[PATCH 07/17] sidput: annotate deprecated
[PATCH 08/17] checkPasswdAccess: annotate deprecated [PATCH 09/17] matchpathcon_init: annotate deprecated [PATCH 10/17] matchpathcon_fini: annotate deprecated [PATCH 11/17] matchpathcon: annotate deprecated
[PATCH 12/17] avc_init: annotate deprecated
[PATCH 13/17] src/selinux_internal.h: fix hidden_proto indents [PATCH 14/17] selinux_internal.h: disable warnings on deprecated [PATCH 15/17] avc_open: mark allowed use of avc_init [PATCH 16/17] src/matchpathcon: allow use of deprecated funcs [PATCH 17/17] utils/matchpathcon: allow use of deprecated funcs
PATCH 1/17 security_load_booleans: update return comment
From: William Roberts <[email protected]>
The code returns -1 not 0, correct it.
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -319,7 +319,7 @@ extern int security_set_boolean_list(size_t boolcnt, SELboolean * boollist, int permanent);/* Load policy boolean settings. Deprecated as local policy booleans no -* longer supported. Will always return 0. +* longer supported. Will always return -1. */ extern int security_load_booleans (char *path);
Signature · 1 line
2.17.1
PATCH 2/17 selinux_booleans_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -321,7 +321,7 @@ extern int security_set_boolean_list(size_t boolcnt,/* Load policy boolean settings. Deprecated as local policy booleans no * longer supported. Will always return -1. */ -extern int security_load_booleans (char *path); +extern int security_load_booleans (char *path) __attribute__ ((deprecated));/* Check the validity of a security context. */ extern int security_check_context (const char * con);
Signature · 1 line
2.17.1
PATCH 3/17 selinux_booleans_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -571,7 +571,7 @@ extern const char *selinux_contexts_path(void);extern const char *selinux_securetty_types_path (void );extern const char *selinux_booleans_subs_path (void );/* Deprecated as local policy booleans no longer supported. */ -extern const char *selinux_booleans_path (void ); +extern const char *selinux_booleans_path (void ) __attribute__ ((deprecated));extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ extern const char *selinux_users_path (void );
Signature · 1 line
2.17.1
PATCH 4/17 selinux_users_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -574,7 +574,7 @@ extern const char *selinux_booleans_subs_path(void);extern const char *selinux_booleans_path (void ) __attribute__ ((deprecated));extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ -extern const char *selinux_users_path (void ); +extern const char *selinux_users_path (void ) __attribute__ ((deprecated));extern const char *selinux_usersconf_path (void );extern const char *selinux_translations_path (void );extern const char *selinux_colors_path (void );
Signature · 1 line
2.17.1
PATCH 5/17 rpm_execcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -629,7 +629,8 @@ extern int setexecfilecon(const char *filename, const char *fallback_type);/* Execute a helper for rpm in an appropriate security context. */ extern int rpm_execcon (unsigned int verified,const char *filename, -char *const argv[],char *const envp[]); +char *const argv[],char *const envp[]) + __attribute__((deprecated ("Use setexecfilecon and execve" )));#endif /* Returns whether a file context is customizable, and should not
Signature · 1 line
2.17.1
PATCH 6/17 sidget: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/avc.h +1 -1
@@ -64,7 +64,7 @@ extern int avc_context_to_sid_raw(const char * ctx, security_id_t * sid);* reference count). Note that avc_context_to_sid() also * increments reference counts. */ -extern int sidget (security_id_t sid); +extern int sidget (security_id_t sid) __attribute__ ((deprecated));/** * sidput - decrement SID reference counter.
Signature · 1 line
2.17.1
PATCH 7/17 sidput: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/avc.h +1 -1
@@ -76,7 +76,7 @@ extern int sidget(security_id_t sid) __attribute__ ((deprecated));* zero, the SID is invalid, and avc_context_to_sid() must * be called to obtain a new SID for the security context. */ -extern int sidput (security_id_t sid); +extern int sidput (security_id_t sid) __attribute__ ((deprecated));/** * avc_get_initial_sid - get SID for an initial kernel security identifier
Signature · 1 line
2.17.1
PATCH 8/17 checkPasswdAccess: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -603,7 +603,8 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ extern int selinux_check_passwd_access (access_vector_t requested); -extern int checkPasswdAccess (access_vector_t requested); +extern int checkPasswdAccess (access_vector_t requested) + __attribute__ ((deprecated ("Use selinux_check_passwd_access" )));/* Check if the tty_context is defined as a securetty Return 0 if secure, < 0 otherwise. */
Signature · 1 line
2.17.1
Stephen Smalley
maintainerRe: [PATCH 08/17] checkPasswdAccess: annotate deprecated
libselinux/include/selinux/selinux.h extern int selinux_check_access(const char * scon, const char * tcon, const char · line 607
Quoted 11 lines · On Tue, Feb 25, 2020 at 3:03 PM <[email protected]> wrote:
libselinux/include/selinux/selinux.h +2
-1@@ -603,7 +603,8 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ extern int selinux_check_passwd_access (access_vector_t requested); -extern int checkPasswdAccess (access_vector_t requested); +extern int checkPasswdAccess (access_vector_t requested) + __attribute__ ((deprecated ("Use selinux_check_passwd_access" )));
I'd actually recommend deprecating that one too and recommending the use of selinux_check_access() instead.
That way they get dynamic lookup of the permission and handling of per-domain permissive and handle_unknown settings.
Only drawback is that they have to call getprevcon_raw() themselves first and pass it in.
PATCH 9/17 matchpathcon_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -457,7 +457,8 @@ extern void set_matchpathcon_flags(unsigned int flags);function also checks for a 'path'.homedirs file and a 'path'.local file and loads additional specifications from them if present. */ -extern int matchpathcon_init (const char *path); +extern int matchpathcon_init (const char *path) + __attribute__ ((deprecated ("Use selabel_open with backend SELABEL_CTX_FILE" )));/* Same as matchpathcon_init, but only load entries with regexes that have stems that are prefixes of 'prefix'. */
Signature · 1 line
2.17.1
PATCH 10/17 matchpathcon_fini: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -465,7 +465,8 @@ extern int matchpathcon_init(const char *path)extern int matchpathcon_init_prefix (const char *path,const char *prefix);/* Free the memory allocated by matchpathcon_init. */ -extern void matchpathcon_fini (void ); +extern void matchpathcon_fini (void ) + __attribute__ ((deprecated ("Use selabel_close" )));/* Resolve all of the symlinks and relative portions of a pathname, but NOT * the final component (same a realpath() unless the final component is a
Signature · 1 line
2.17.1
PATCH 11/17 matchpathcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -480,7 +480,8 @@ extern int realpath_not_final(const char *name, char *resolved_path);If matchpathcon_init has not already been called, then this function will call it upon its first invocation with a NULL path. */ extern int matchpathcon (const char *path, -mode_t mode,char ** con); +mode_t mode,char ** con) + __attribute__ ((deprecated ("Use selabel_lookup instead" )));/* Same as above, but return a specification index for later use in a matchpathcon_filespec_add() call - see below. */
Signature · 1 line
2.17.1
PATCH 12/17 avc_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +2 -1
@@ -192,7 +192,8 @@ extern int avc_init(const char *msgprefix,const struct avc_memory_callback *mem_callbacks, const struct avc_log_callback *log_callbacks, const struct avc_thread_callback *thread_callbacks, - const struct avc_lock_callback *lock_callbacks); + const struct avc_lock_callback *lock_callbacks) + __attribute__ ((deprecated("Use avc_open and selinux_set_callback")));/** * avc_open - Initialize the AVC.
Signature · 1 line
2.17.1
PATCH 13/17 src/selinux_internal.h: fix hidden_proto indents
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/src/selinux_internal.h | 190 +++++++++++++++--------------- 1 file changed, 95 insertions(+), 95 deletions(-)
libselinux/src/selinux_internal.h +95 -95
@@ -3,107 +3,107 @@#include "dso.h" hidden_proto (selinux_mkload_policy) - hidden_proto(fini_selinuxmnt) - hidden_proto(set_selinuxmnt) - hidden_proto(selinuxfs_exists) - hidden_proto(security_disable) - hidden_proto(security_policyvers) - hidden_proto(security_load_policy) - hidden_proto(security_get_boolean_active) - hidden_proto(security_get_boolean_names) - hidden_proto(security_set_boolean) - hidden_proto(security_commit_booleans) - hidden_proto(security_check_context) - hidden_proto(security_check_context_raw) - hidden_proto(security_canonicalize_context) - hidden_proto(security_canonicalize_context_raw) - hidden_proto(security_compute_av) - hidden_proto(security_compute_av_raw) - hidden_proto(security_compute_av_flags) - hidden_proto(security_compute_av_flags_raw) - hidden_proto(security_compute_user) - hidden_proto(security_compute_user_raw) - hidden_proto(security_compute_create) - hidden_proto(security_compute_create_raw) - hidden_proto(security_compute_create_name) - hidden_proto(security_compute_create_name_raw) - hidden_proto(security_compute_member_raw) - hidden_proto(security_compute_relabel_raw) - hidden_proto(security_validatetrans) - hidden_proto(security_validatetrans_raw) - hidden_proto(is_selinux_enabled) - hidden_proto(is_selinux_mls_enabled) - hidden_proto(freecon) - hidden_proto(freeconary) - hidden_proto(getprevcon) - hidden_proto(getprevcon_raw) - hidden_proto(getcon) - hidden_proto(getcon_raw) - hidden_proto(setcon_raw) - hidden_proto(getpeercon_raw) - hidden_proto(getpidcon_raw) - hidden_proto(getexeccon_raw) - hidden_proto(getfilecon) - hidden_proto(getfilecon_raw) - hidden_proto(lgetfilecon_raw) - hidden_proto(fgetfilecon_raw) - hidden_proto(setfilecon_raw) - hidden_proto(lsetfilecon_raw) - hidden_proto(fsetfilecon_raw) - hidden_proto(setexeccon) - hidden_proto(setexeccon_raw) - hidden_proto(getfscreatecon_raw) - hidden_proto(getkeycreatecon_raw) - hidden_proto(getsockcreatecon_raw) - hidden_proto(setfscreatecon_raw) - hidden_proto(setkeycreatecon_raw) - hidden_proto(setsockcreatecon_raw) - hidden_proto(security_getenforce) - hidden_proto(security_setenforce) - hidden_proto(security_deny_unknown) - hidden_proto(security_reject_unknown) - hidden_proto(security_get_checkreqprot) - hidden_proto(selinux_boolean_sub) - hidden_proto(selinux_current_policy_path) - hidden_proto(selinux_binary_policy_path) - hidden_proto(selinux_booleans_subs_path) - hidden_proto(selinux_default_context_path) - hidden_proto(selinux_securetty_types_path) - hidden_proto(selinux_failsafe_context_path) - hidden_proto(selinux_removable_context_path) - hidden_proto(selinux_virtual_domain_context_path) - hidden_proto(selinux_virtual_image_context_path) - hidden_proto(selinux_lxc_contexts_path) - hidden_proto(selinux_file_context_path) - hidden_proto(selinux_file_context_homedir_path) - hidden_proto(selinux_file_context_local_path) - hidden_proto(selinux_file_context_subs_dist_path) - hidden_proto(selinux_file_context_subs_path) - hidden_proto(selinux_netfilter_context_path) - hidden_proto(selinux_homedir_context_path) - hidden_proto(selinux_user_contexts_path) - hidden_proto(selinux_booleans_path) - hidden_proto(selinux_customizable_types_path) - hidden_proto(selinux_media_context_path) - hidden_proto(selinux_x_context_path) - hidden_proto(selinux_sepgsql_context_path) - hidden_proto(selinux_openrc_contexts_path) - hidden_proto(selinux_openssh_contexts_path) - hidden_proto(selinux_snapperd_contexts_path) - hidden_proto(selinux_systemd_contexts_path) - hidden_proto(selinux_path) - hidden_proto(selinux_check_passwd_access) - hidden_proto(selinux_check_securetty_context) - hidden_proto(matchpathcon_init_prefix) - hidden_proto(selinux_users_path) - hidden_proto(selinux_usersconf_path); +hidden_proto(fini_selinuxmnt) +hidden_proto(set_selinuxmnt) +hidden_proto(selinuxfs_exists) +hidden_proto(security_disable) +hidden_proto(security_policyvers) +hidden_proto(security_load_policy) +hidden_proto(security_get_boolean_active) +hidden_proto(security_get_boolean_names) +hidden_proto(security_set_boolean) +hidden_proto(security_commit_booleans) +hidden_proto(security_check_context) +hidden_proto(security_check_context_raw) +hidden_proto(security_canonicalize_context) +hidden_proto(security_canonicalize_context_raw) +hidden_proto(security_compute_av) +hidden_proto(security_compute_av_raw) +hidden_proto(security_compute_av_flags) +hidden_proto(security_compute_av_flags_raw) +hidden_proto(security_compute_user) +hidden_proto(security_compute_user_raw) +hidden_proto(security_compute_create) +hidden_proto(security_compute_create_raw) +hidden_proto(security_compute_create_name) +hidden_proto(security_compute_create_name_raw) +hidden_proto(security_compute_member_raw) +hidden_proto(security_compute_relabel_raw) +hidden_proto(security_validatetrans) +hidden_proto(security_validatetrans_raw) +hidden_proto(is_selinux_enabled) +hidden_proto(is_selinux_mls_enabled) +hidden_proto(freecon) +hidden_proto(freeconary) +hidden_proto(getprevcon) +hidden_proto(getprevcon_raw) +hidden_proto(getcon) +hidden_proto(getcon_raw) +hidden_proto(setcon_raw) +hidden_proto(getpeercon_raw) +hidden_proto(getpidcon_raw) +hidden_proto(getexeccon_raw) +hidden_proto(getfilecon) +hidden_proto(getfilecon_raw) +hidden_proto(lgetfilecon_raw) +hidden_proto(fgetfilecon_raw) +hidden_proto(setfilecon_raw) +hidden_proto(lsetfilecon_raw) +hidden_proto(fsetfilecon_raw) +hidden_proto(setexeccon) +hidden_proto(setexeccon_raw) +hidden_proto(getfscreatecon_raw) +hidden_proto(getkeycreatecon_raw) +hidden_proto(getsockcreatecon_raw) +hidden_proto(setfscreatecon_raw) +hidden_proto(setkeycreatecon_raw) +hidden_proto(setsockcreatecon_raw) +hidden_proto(security_getenforce) +hidden_proto(security_setenforce) +hidden_proto(security_deny_unknown) +hidden_proto(security_reject_unknown) +hidden_proto(security_get_checkreqprot) +hidden_proto(selinux_boolean_sub) +hidden_proto(selinux_current_policy_path) +hidden_proto(selinux_binary_policy_path) +hidden_proto(selinux_booleans_subs_path) +hidden_proto(selinux_default_context_path) +hidden_proto(selinux_securetty_types_path) +hidden_proto(selinux_failsafe_context_path) +hidden_proto(selinux_removable_context_path) +hidden_proto(selinux_virtual_domain_context_path) +hidden_proto(selinux_virtual_image_context_path) +hidden_proto(selinux_lxc_contexts_path) +hidden_proto(selinux_file_context_path) +hidden_proto(selinux_file_context_homedir_path) +hidden_proto(selinux_file_context_local_path) +hidden_proto(selinux_file_context_subs_dist_path) +hidden_proto(selinux_file_context_subs_path) +hidden_proto(selinux_netfilter_context_path) +hidden_proto(selinux_homedir_context_path) +hidden_proto(selinux_user_contexts_path) +hidden_proto(selinux_booleans_path) +hidden_proto(selinux_customizable_types_path) +hidden_proto(selinux_media_context_path) +hidden_proto(selinux_x_context_path) +hidden_proto(selinux_sepgsql_context_path) +hidden_proto(selinux_openrc_contexts_path) +hidden_proto(selinux_openssh_contexts_path) +hidden_proto(selinux_snapperd_contexts_path) +hidden_proto(selinux_systemd_contexts_path) +hidden_proto(selinux_path) +hidden_proto(selinux_check_passwd_access) +hidden_proto(selinux_check_securetty_context) +hidden_proto(matchpathcon_init_prefix) +hidden_proto(selinux_users_path) +hidden_proto(selinux_usersconf_path);hidden_proto (selinux_translations_path);hidden_proto (selinux_colors_path);hidden_proto (selinux_getenforcemode);hidden_proto (selinux_getpolicytype);hidden_proto (selinux_raw_to_trans_context);hidden_proto (selinux_trans_to_raw_context); -hidden_proto (selinux_raw_context_to_color); +hidden_proto (selinux_raw_context_to_color);hidden_proto (security_get_initial_context);hidden_proto (security_get_initial_context_raw);hidden_proto (selinux_reset_config);
Signature · 1 line
2.17.1
PATCH 14/17 selinux_internal.h: disable warnings on deprecated
In reply to [email protected]From: William Roberts <[email protected]>
selinux_internal.h marks the visibility of symbols, many of these are the deprecated routines that get marked as hidden. This causes compilers to warn about deprecated uses. However this is a valid annotation that we want to keep, until the functions are finally removed.
--- libselinux/src/selinux_internal.h | 8 ++++++++ 1 file changed, 8 insertions(+)
libselinux/src/selinux_internal.h +8 -0
@@ -2,6 +2,12 @@#include <pthread.h> #include "dso.h" +/* +* Disable deprecated warnings for users internal to the library. +*/ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + hidden_proto(selinux_mkload_policy) hidden_proto(fini_selinuxmnt) hidden_proto(set_selinuxmnt)
@@ -181,3 +187,5 @@ extern int selinux_page_size hidden;#define SELINUXCONFIG SELINUXDIR "config" extern int has_selinux_config hidden; + +#pragma GCC diagnostic pop
Signature · 1 line
2.17.1
PATCH 15/17 avc_open: mark allowed use of avc_init
In reply to [email protected]From: William Roberts <[email protected]>
avc_init is deprecated, however avc_open internally uses it. Mark this deprecated use as OK. Another approach could be to define an avc_init2 as a hidden, internal symbol and call that, but this was seemed simpler and clear.
--- libselinux/src/avc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libselinux/src/avc.c +3 -1
@@ -156,8 +156,10 @@ int avc_open(struct selinux_opt *opts, unsigned nopts) avc_enforcing = !!opts[nopts].value;break ; } - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"return avc_init ("avc" ,NULL ,NULL ,NULL ,NULL ); +#pragma GCC diagnostic pop } int avc_init(const char *prefix,
Signature · 1 line
2.17.1
PATCH 16/17 src/matchpathcon: allow use of deprecated funcs
In reply to [email protected]From: William Roberts <[email protected]>
Internally users of deprecated functions are ok so allow it.
--- libselinux/src/matchpathcon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
libselinux/src/matchpathcon.c +6 -1
@@ -317,7 +317,10 @@ void matchpathcon_filespec_destroy(void)static void matchpathcon_thread_destructor (void __attribute__((unused)) *ptr) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"matchpathcon_fini (); +#pragma GCC diagnostic pop }void __attribute__((destructor))matchpathcon_lib_destructor (void );
@@ -451,8 +454,10 @@ int matchpathcon(const char *path, mode_t mode, char ** con)int matchpathcon_index (const char *name,mode_t mode,char ** con) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"int i =matchpathcon (name, mode, con); - +#pragma GCC diagnostic popif (i <0 )return -1 ;
Signature · 1 line
2.17.1
PATCH 17/17 utils/matchpathcon: allow use of deprecated funcs
In reply to [email protected]From: William Roberts <[email protected]>
Internally users of deprecated functions are ok so allow it.
--- libselinux/utils/matchpathcon.c | 9 +++++++++ 1 file changed, 9 insertions(+)
libselinux/utils/matchpathcon.c +9 -0
@@ -22,7 +22,10 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname)static int printmatchpathcon (const char *path,int header,int mode) {char *buf; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"int rc =matchpathcon (path, mode, &buf); +#pragma GCC diagnostic popif (rc <0 ) {if (errno ==ENOENT ) { buf =strdup ("<<none>>" );
@@ -103,7 +106,10 @@ int main(int argc, char **argv)exit (1 ); } init =1 ; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"if (matchpathcon_init (optarg)) { +#pragma GCC diagnostic pop fprintf(stderr, "Error while processing %s: %s\n", optarg,
@@ -195,6 +201,9 @@ int main(int argc, char **argv) error |=printmatchpathcon (path, header, mode); } } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"matchpathcon_fini (); +#pragma GCC diagnostic popreturn error; }
Signature · 1 line
2.17.1
Stephen Smalley
maintainerQuoted 9 lines · On Tue, Feb 25, 2020 at 3:03 PM <[email protected]> wrote:
The annoying part is internal users of the routines. We could always make a v2 version of the function for internal callers, and leave the old interfaces intact to work around the warnings, or just pragma them out. This series pragma's them out.
diagnostic push has been supported since GCC v4.6. Earlier versions will warn on this, and the sideffect is that the diagnostic ignored pragma will be valid for the rest of the file. Clang has similair support thats been around *at least* since clang 6.0.
My inclination (and others are free to disagree) would be to rename the deprecated functions for internal users (and mark them hidden), and add stubs for the old interfaces that call the hidden functions to avoid the need for this pragma. Also, FWIW, there is a push to remove the hidden_def/hidden_proto stuff for LTO, see
https://github.com/SELinuxProject/selinux/issues/204, although I don't yet know how that will turn out for libselinux.
Quoted 12 lines · Stephen Smalley
Quoted 9 lines · On Tue, Feb 25, 2020 at 3:03 PM <[email protected]> wrote:
The annoying part is internal users of the routines. We could always make a v2 version of the function for internal callers, and leave the old interfaces intact to work around the warnings, or just pragma them out. This series pragma's them out.
diagnostic push has been supported since GCC v4.6. Earlier versions will warn on this, and the sideffect is that the diagnostic ignored pragma will be valid for the rest of the file. Clang has similair support thats been around *at least* since clang 6.0.
Quoted 4 lines
My inclination (and others are free to disagree) would be to rename the deprecated functions for internal users (and mark them hidden), and add stubs for the old interfaces that call the hidden functions to avoid the need for this pragma.
I'm actually leaning that way myself after thinking about it more.
Quoted 4 lines
Also, FWIW, there is a push to remove
the hidden_def/hidden_proto stuff for LTO, see
https://github.com/SELinuxProject/selinux/issues/204, although I don't yet know how that will turn out for libselinux.
Good to know.
Quoted 15 lines · William Roberts
Quoted 12 lines · Stephen Smalley
Quoted 9 lines · On Tue, Feb 25, 2020 at 3:03 PM <[email protected]> wrote:
The annoying part is internal users of the routines. We could always make a v2 version of the function for internal callers, and leave the old interfaces intact to work around the warnings, or just pragma them out. This series pragma's them out.
diagnostic push has been supported since GCC v4.6. Earlier versions will warn on this, and the sideffect is that the diagnostic ignored pragma will be valid for the rest of the file. Clang has similair support thats been around *at least* since clang 6.0.
Quoted 6 lines
Quoted 4 lines
My inclination (and others are free to disagree) would be to rename the deprecated functions for internal users (and mark them hidden), and add stubs for the old interfaces that call the hidden functions to avoid the need for this pragma.
I'm actually leaning that way myself after thinking about it more.
It doesn't get us around all the issues, anything marked deprecated in selinux.h and marked hidden_proto in selinux_internal.h, will still need a pragma.
This would be much simpler if we drop the whole hidden_proto stuff, I guess kloczek is proposing patches? Who is that, I see the Github name as:
Tomasz Kłoczko
But I can't find any matching author in the git logs to CC them.
I'm looking at those macros:hidden_defhidden_proto
They both seem to take a function and create an _internal symbol, and set the global symbol equal to the internal one. Essentially, both the normal and _internal functions are pointing to the same address.
$ readelf -s ./src/libselinux.so | grep setexeccon_raw 176: 0000000000017c26 63 FUNC GLOBAL DEFAULT 12 setexeccon_raw 279: 0000000000017c26 63 FUNC LOCAL DEFAULT 12 setexeccon_raw_internal 606: 0000000000017c26 63 FUNC GLOBAL DEFAULT 12 setexeccon_raw
The hidden one, additionally
sets the visibility to hidden, which if IIUC, just requires one to statically link. We can see above the
visibility is local.
What I don't understand, is why one would do this? What actual performance enhancement do we get?
Quoted 7 lines
Quoted 5 lines
Also, FWIW, there is a push to remove
the hidden_def/hidden_proto stuff for LTO, see
https://github.com/SELinuxProject/selinux/issues/204, although I don't yet know how that will turn out for libselinux.Good to know.
Stephen Smalley
maintainerQuoted 8 lines · William Roberts
It doesn't get us around all the issues, anything marked deprecated in
selinux.hand markedhidden_protoinselinux_internal.h, will still need a pragma.This would be much simpler if we drop the whole
hidden_protostuff, I guess kloczek is proposing patches? Who is that, I see the Github name as:
Tomasz KłoczkoBut I can't find any matching author in the git logs to CC them.
I don't actually know him myself but he has opened a number of issues on the selinux userspace and appears to be involved in Fedora in some capacity.
Quoted 14 lines
I'm looking at those macros:
hidden_defhidden_protoThey both seem to take a function and create an
_internalsymbol, and set the global symbol equal to the internal one. Essentially, both the normal and_internalfunctions are pointing to the same address.$ readelf -s ./src/libselinux.so | grep setexeccon_raw 176: 0000000000017c26 63 FUNC GLOBAL DEFAULT 12 setexeccon_raw 279: 0000000000017c26 63 FUNC LOCAL DEFAULT 12 setexeccon_raw_internal 606: 0000000000017c26 63 FUNC GLOBAL DEFAULT 12 setexeccon_raw
Quoted 7 lines
The hidden one, additionally
sets the visibility to hidden, which if IIUC, just requires one to statically link. We can see above the
visibility is local.What I don't understand, is why one would do this? What actual performance enhancement do we get?
The hidden_def/hidden_proto stuff originally came from Ulrich Drepper, glibc maintainer at the time, to eliminate unnecessary runtime relocations and PLT entries being used for local symbols. Per the comments in https://github.com/SELinuxProject/selinux/issues/204,
these might not be needed anymore and are breaking building with LTO. Willing to get rid of them if it doesn't produce a significant regression.
(Adding Ulrich himself to Cc...)
Quoted 38 lines · Stephen Smalley
Quoted 8 lines · William Roberts
It doesn't get us around all the issues, anything marked deprecated in
selinux.hand markedhidden_protoinselinux_internal.h, will still need a pragma.This would be much simpler if we drop the whole
hidden_protostuff, I guess kloczek is proposing patches? Who is that, I see the Github name as:
Tomasz KłoczkoBut I can't find any matching author in the git logs to CC them.
I don't actually know him myself but he has opened a number of issues on the selinux userspace and appears to be involved in Fedora in some capacity.
Quoted 14 lines
I'm looking at those macros:
hidden_defhidden_protoThey both seem to take a function and create an
_internalsymbol, and set the global symbol equal to the internal one. Essentially, both the normal and_internalfunctions are pointing to the same address.$ readelf -s ./src/libselinux.so | grep setexeccon_raw 176: 0000000000017c26 63 FUNC GLOBAL DEFAULT 12 setexeccon_raw 279: 0000000000017c26 63 FUNC LOCAL DEFAULT 12 setexeccon_raw_internal 606: 0000000000017c26 63 FUNC GLOBAL DEFAULT 12 setexeccon_rawQuoted 7 lines
The hidden one, additionally
sets the visibility to hidden, which if IIUC, just requires one to statically link. We can see above the
visibility is local.What I don't understand, is why one would do this? What actual performance enhancement do we get?
Quoted 7 lines
The hidden_def/hidden_proto stuff originally came from Ulrich Drepper, glibc maintainer at the time, to eliminate unnecessary runtime relocations and PLT entries being used for local symbols. Per the comments in https://github.com/SELinuxProject/selinux/issues/204,
these might not be needed anymore and are breaking building with LTO. Willing to get rid of them if it doesn't produce a significant regression.
Ulrich, could you help us understand the macros you proposed to add to the SELinux libraries (probably a very long time ago)? Specifically, we are talking about those defined in "dso.h" header files such as this one [1]. See also GH issue 204 [2] for related discussion.
Thanks,
[1] https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/dso.h
[2] https://github.com/SELinuxProject/selinux/issues/204
Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com> Software Engineer, Security Technologies Red Hat, Inc.
<snip>
Quoted 7 lines
Quoted 7 lines
The hidden_def/hidden_proto stuff originally came from Ulrich Drepper, glibc maintainer at the time, to eliminate unnecessary runtime relocations and PLT entries being used for local symbols. Per the comments in https://github.com/SELinuxProject/selinux/issues/204,
these might not be needed anymore and are breaking building with LTO. Willing to get rid of them if it doesn't produce a significant regression.
I guess that's my major question, how do we determine this is a regression? Obviously a functional break is self explanatory.
Quoted 16 lines
Ulrich, could you help us understand the macros you proposed to add to the SELinux libraries (probably a very long time ago)? Specifically, we are talking about those defined in "
dso.h" header files such as this one [1]. See also GH issue 204 [2] for related discussion.Thanks,
[1] https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/dso.h
[2] https://github.com/SELinuxProject/selinux/issues/204--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
Stephen Smalley
maintainerQuoted 10 lines · William Roberts
<snip>
Quoted 7 lines
Quoted 7 lines
The hidden_def/hidden_proto stuff originally came from Ulrich Drepper, glibc maintainer at the time, to eliminate unnecessary runtime relocations and PLT entries being used for local symbols. Per the comments in https://github.com/SELinuxProject/selinux/issues/204,
these might not be needed anymore and are breaking building with LTO. Willing to get rid of them if it doesn't produce a significant regression.
Quoted 2 lines
I guess that's my major question, how do we determine this is a regression? Obviously a functional break is self explanatory.
The original statistics used to justify it were generated by the relinfo.pl script available from
https://www.akkadia.org/drepper/relinfo.pl.
Quoted 4 lines · Ondrej Mosnacek
Ulrich, could you help us understand the macros you proposed to add to the SELinux libraries (probably a very long time ago)? Specifically, we are talking about those defined in "
dso.h" header files such as this one [1]. See also GH issue 204 [2] for related discussion.
The use of the hidden infrastructure is not just a means to reduce overhead in the form of PLTs. It also ensures that internals for the library don't leak out. If calls between functions within the same DSO use the PLT they can be intercepted by DSO earlier in the search path of the dynamic linker. This can have unwanted consequences.
I advise that this isn't changed. The infrastructure to do this should change, though. You could look at the code glibc uses today. The functionality is still there, just slightly changed.
An alternative is to use gcc's -fno-semantic-interposition option. This should ensure that PLT entries are avoided. For Python this was used to achieve significant speedups due to the PLT reduction. I know you don't care about speed that much but this is a way to achieve it. Python uses LTO but since the compiler is told about the symbol use there are not problems.
Quoted 10 lines · Ulrich Drepper
Quoted 4 lines · Ondrej Mosnacek
Ulrich, could you help us understand the macros you proposed to add to the SELinux libraries (probably a very long time ago)? Specifically, we are talking about those defined in "
dso.h" header files such as this one [1]. See also GH issue 204 [2] for related discussion.The use of the hidden infrastructure is not just a means to reduce overhead in the form of PLTs. It also ensures that internals for the library don't leak out.
Linker script? We just use a map file that has everything local except for what we want to export.
Quoted 3 lines
If calls between functions within the same DSO
use the PLT they can be intercepted by DSO earlier in the search path of the dynamic linker. This can have unwanted consequences.
Huh? I'm not following? If we just remove this, what would actually break in libselinux?
Quoted 11 lines
I advise that this isn't changed. The infrastructure to do this should change, though. You could look at the code glibc uses today. The functionality is still there, just slightly changed.
An alternative is to use gcc's -fno-semantic-interposition option. This should ensure that PLT entries are avoided. For Python this was used to achieve significant speedups due to the PLT reduction. I know you don't care about speed that much but this is a way to achieve it. Python uses LTO but since the compiler is told about the symbol use there are not problems.
This minor overhead on the first call to a routine to resolve the symbol isn't really much overhead. After it's resolved its like an extra jmp or something.
If you really wanted to avoid relocation, couldn't you just link statically?
This seems like it might be good for specific issues, but I don't see how this infrastructure really prevents or fixes anything besides complicating the code, perhaps enlighten me?
I can see how perhaps for large things like python/glibc it could be useful but for
libselinux this just seems like an over-engineered solution to a non-existent problem.
Stephen Smalley
maintainerQuoted 8 lines · William Roberts
Quoted 3 lines · Ulrich Drepper
The use of the hidden infrastructure is not just a means to reduce overhead in the form of PLTs. It also ensures that internals for the library don't leak out.
Linker script? We just use a map file that has everything local except for what we want to export.
That just controls what is exported. The hidden_proto/hidden_def stuff is to ensure that when libselinux calls one of its own exported symbols, that symbol resolves to the actual libselinux implementation and not something provided by some other DSO earlier in the search path, which is otherwise possible.
Quoted 9 lines · Stephen Smalley
Quoted 6 lines · William Roberts
Quoted 3 lines · Ulrich Drepper
The use of the hidden infrastructure is not just a means to reduce overhead in the form of PLTs. It also ensures that internals for the library don't leak out.
Quoted 8 lines
Quoted 2 lines
Linker script? We just use a map file that has everything local except for what we want to export.
That just controls what is exported. The hidden_proto/hidden_def stuff is to ensure that when libselinux calls one of its own exported symbols, that symbol resolves to the actual libselinux implementation and not something provided by some other DSO earlier in the search path, which is otherwise possible.
Sure, but do we actually care about that?
If we actually do care, we could throw a script in the build to make sure anything in the linker script map is not used internally.
Right now, all this DSO hygiene and look up protection is opt-in, which usually always results in missed cases. With the linker script, it's opt-out, which is usually always how you want to do things.
Stephen Smalley
maintainerQuoted 9 lines · William Roberts
Quoted 5 lines · Stephen Smalley
That just controls what is exported. The hidden_proto/hidden_def stuff is to ensure that when libselinux calls one of its own exported symbols, that symbol resolves to the actual libselinux implementation and not something provided by some other DSO earlier in the search path, which is otherwise possible.
Quoted 8 lines
Sure, but do we actually care about that?
If we actually do care, we could throw a script in the build to make sure anything in the linker script map is not used internally.
Right now, all this DSO hygiene and look up protection is opt-in, which usually always results in missed cases. With the linker script, it's opt-out, which is usually always how you want to do things.
There are lots of cases where libselinux calls one of its own exported symbols, so you can't just prohibit that. -fno-semantic-interposition sounds like the right solution to me, and appears to be the default in clang.
Dropping the hidden_def/hidden_proto stuff without enabling -fno-semantic-interposition could potentially break because libselinux could suddenly start using some external implementation of one of its own functions.
Adding a map file and defaulting to hidden visibility would be a good idea but is separate.
Quoted 17 lines · Stephen Smalley
Quoted 14 lines · William Roberts
Quoted 5 lines · Stephen Smalley
That just controls what is exported. The hidden_proto/hidden_def stuff is to ensure that when libselinux calls one of its own exported symbols, that symbol resolves to the actual libselinux implementation and not something provided by some other DSO earlier in the search path, which is otherwise possible.
Sure, but do we actually care about that?
If we actually do care, we could throw a script in the build to make sure anything in the linker script map is not used internally.
Quoted 8 lines
Quoted 3 lines
Right now, all this DSO hygiene and look up protection is opt-in, which usually always results in missed cases. With the linker script, it's opt-out, which is usually always how you want to do things.
There are lots of cases where libselinux calls one of its own exported symbols, so you can't just prohibit that. -fno-semantic-interposition sounds like the right solution to me, and appears to be the default in clang.
Interesting to note.
Quoted 4 lines
Dropping the hidden_def/hidden_proto stuff without enabling -fno-semantic-interposition could potentially break because libselinux could suddenly start using some external implementation of one of its own functions.
Conjecture.
Quoted 2 lines
Adding a map file and defaulting to hidden visibility would be a good idea but is separate.
IIUC, not really, the current code attempts to limit our exported symbols.
You would need both the compiler option and a map file to keep functional parity with whats there. Which is fine, that's easy enough to do and should be some welcome housekeeping.
Quoted 2 lines · William Roberts
Linker script? We just use a map file that has everything local except for what we want to export.
That's not the same. If you call an exported function that call might actually end up somewhere else.
Quoted 2 lines
Huh? I'm not following? If we just remove this, what would actually break in libselinux?
It's not breaking anything per-se. It can break something if a symbol is inadvertently or deliberately defined elsewhere.
Quoted 2 lines
This minor overhead on the first call to a routine to resolve the symbol isn't really much overhead. After it's resolved its like an extra jmp or something.
It's not as much about the overhead of the lookup. The indirect calls are expensive. And so is the loss of opportunities to optimize for the compiler.
Quoted 1 line
If you really wanted to avoid relocation, couldn't you just link statically?
Aside from the fact that you don't have the whole picture linking statically is problematic:
https://akkadia.org/drepper/no_static_linking.html
Quoted 3 lines
This seems like it might be good for specific issues, but I don't see how this infrastructure really prevents or fixes anything besides complicating the code, perhaps enlighten me?
Again, it's a semantic change in addition to a performance regression. Didn't you read the part where I suggested just using this one compiler option? How much less work are you willing to invest?
<snip>
Quoted 9 lines
Quoted 4 lines
This seems like it might be good for specific issues, but I don't see how this infrastructure really prevents or fixes anything besides complicating the code, perhaps enlighten me?
Again, it's a semantic change in addition to a performance regression. Didn't you read the part where I suggested just using this one compiler option? How much less work are you willing to invest?
No I saw that, and it's it's fine and all and we can add it, but it limits us to gcc 5.3+.
But we would still need a map file for basic hygiene on what we are exporting.
But this still seems like solving a problem that practically doesn't exist.
V2:
- Simplified now that dso.h stuff has been removed.
- selinux_check_passwd_access has been deprecated and now both selinux_check_passwd_access and checkPasswdAccess are recomending selinux_check_access.
- matchpathcon is linked statically to get access to deprecated routines and prints a deprecated warning to stderr.
V1:
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.
External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared here
int foo(void) {
^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {
[PATCH v2 01/18] security_load_booleans: update return comment [PATCH v2 02/18] security_load_booleans: annotate deprecated [PATCH v2 03/18] selinux_booleans_path: annotate deprecated [PATCH v2 04/18] selinux_users_path: annotate deprecated [PATCH v2 05/18] rpm_execcon: annotate deprecated
[PATCH v2 06/18] sidget: annotate deprecated
[PATCH v2 07/18] sidput: annotate deprecated
[PATCH v2 08/18] checkPasswdAccess: annotate deprecated [PATCH v2 09/18] matchpathcon_init: annotate deprecated [PATCH v2 10/18] matchpathcon_fini: annotate deprecated [PATCH v2 11/18] matchpathcon: annotate deprecated
[PATCH v2 12/18] avc_init: annotate deprecated
[PATCH v2 13/18] avc: create internal avc_init interface [PATCH v2 14/18] matchpathcon: create internal matchpathcon_fini [PATCH v2 15/18] matchpathcon: create internal matchpathcon interface [PATCH v2 16/18] selinux_check_passwd_access: annotate deprecated [PATCH v2 17/18] utils: matchpathcon to use interal interfaces [PATCH v2 18/18] utils: matchpathcon add deprecated warning
PATCH v2 1/18 security_load_booleans: update return comment
From: William Roberts <[email protected]>
The code returns -1 not 0, correct it.
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -323,7 +323,7 @@ extern int security_set_boolean_list(size_t boolcnt, SELboolean * boollist, int permanent);/* Load policy boolean settings. Deprecated as local policy booleans no -* longer supported. Will always return 0. +* longer supported. Will always return -1. */ extern int security_load_booleans (char *path);
Signature · 1 line
2.17.1
PATCH v2 2/18 security_load_booleans: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -325,7 +325,7 @@ extern int security_set_boolean_list(size_t boolcnt,/* Load policy boolean settings. Deprecated as local policy booleans no * longer supported. Will always return -1. */ -extern int security_load_booleans (char *path); +extern int security_load_booleans (char *path) __attribute__ ((deprecated));/* Check the validity of a security context. */ extern int security_check_context (const char * con);
Signature · 1 line
2.17.1
PATCH v2 3/18 selinux_booleans_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -575,7 +575,7 @@ extern const char *selinux_contexts_path(void);extern const char *selinux_securetty_types_path (void );extern const char *selinux_booleans_subs_path (void );/* Deprecated as local policy booleans no longer supported. */ -extern const char *selinux_booleans_path (void ); +extern const char *selinux_booleans_path (void ) __attribute__ ((deprecated));extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ extern const char *selinux_users_path (void );
Signature · 1 line
2.17.1
PATCH v2 4/18 selinux_users_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -578,7 +578,7 @@ extern const char *selinux_booleans_subs_path(void);extern const char *selinux_booleans_path (void ) __attribute__ ((deprecated));extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ -extern const char *selinux_users_path (void ); +extern const char *selinux_users_path (void ) __attribute__ ((deprecated));extern const char *selinux_usersconf_path (void );extern const char *selinux_translations_path (void );extern const char *selinux_colors_path (void );
Signature · 1 line
2.17.1
PATCH v2 5/18 rpm_execcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -633,7 +633,8 @@ extern int setexecfilecon(const char *filename, const char *fallback_type);/* Execute a helper for rpm in an appropriate security context. */ extern int rpm_execcon (unsigned int verified,const char *filename, -char *const argv[],char *const envp[]); +char *const argv[],char *const envp[]) + __attribute__((deprecated ("Use setexecfilecon and execve" )));#endif /* Returns whether a file context is customizable, and should not
Signature · 1 line
2.17.1
PATCH v2 6/18 sidget: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/avc.h +1 -1
@@ -64,7 +64,7 @@ extern int avc_context_to_sid_raw(const char * ctx, security_id_t * sid);* reference count). Note that avc_context_to_sid() also * increments reference counts. */ -extern int sidget (security_id_t sid); +extern int sidget (security_id_t sid) __attribute__ ((deprecated));/** * sidput - decrement SID reference counter.
Signature · 1 line
2.17.1
PATCH v2 7/18 sidput: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/avc.h +1 -1
@@ -76,7 +76,7 @@ extern int sidget(security_id_t sid) __attribute__ ((deprecated));* zero, the SID is invalid, and avc_context_to_sid() must * be called to obtain a new SID for the security context. */ -extern int sidput (security_id_t sid); +extern int sidput (security_id_t sid) __attribute__ ((deprecated));/** * avc_get_initial_sid - get SID for an initial kernel security identifier
Signature · 1 line
2.17.1
PATCH v2 8/18 checkPasswdAccess: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -607,7 +607,8 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ extern int selinux_check_passwd_access (access_vector_t requested); -extern int checkPasswdAccess (access_vector_t requested); +extern int checkPasswdAccess (access_vector_t requested) + __attribute__ ((deprecated ("Use selinux_check_access" )));/* Check if the tty_context is defined as a securetty Return 0 if secure, < 0 otherwise. */
Signature · 1 line
2.17.1
PATCH v2 9/18 matchpathcon_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -461,7 +461,8 @@ extern void set_matchpathcon_flags(unsigned int flags);function also checks for a 'path'.homedirs file and a 'path'.local file and loads additional specifications from them if present. */ -extern int matchpathcon_init (const char *path); +extern int matchpathcon_init (const char *path) + __attribute__ ((deprecated ("Use selabel_open with backend SELABEL_CTX_FILE" )));/* Same as matchpathcon_init, but only load entries with regexes that have stems that are prefixes of 'prefix'. */
Signature · 1 line
2.17.1
PATCH v2 10/18 matchpathcon_fini: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -469,7 +469,8 @@ extern int matchpathcon_init(const char *path)extern int matchpathcon_init_prefix (const char *path,const char *prefix);/* Free the memory allocated by matchpathcon_init. */ -extern void matchpathcon_fini (void ); +extern void matchpathcon_fini (void ) + __attribute__ ((deprecated ("Use selabel_close" )));/* Resolve all of the symlinks and relative portions of a pathname, but NOT * the final component (same a realpath() unless the final component is a
Signature · 1 line
2.17.1
PATCH v2 11/18 matchpathcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +2 -1
@@ -484,7 +484,8 @@ extern int realpath_not_final(const char *name, char *resolved_path);If matchpathcon_init has not already been called, then this function will call it upon its first invocation with a NULL path. */ extern int matchpathcon (const char *path, -mode_t mode,char ** con); +mode_t mode,char ** con) + __attribute__ ((deprecated ("Use selabel_lookup instead" )));/* Same as above, but return a specification index for later use in a matchpathcon_filespec_add() call - see below. */
Signature · 1 line
2.17.1
PATCH v2 12/18 avc_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +2 -1
@@ -192,7 +192,8 @@ extern int avc_init(const char *msgprefix,const struct avc_memory_callback *mem_callbacks, const struct avc_log_callback *log_callbacks, const struct avc_thread_callback *thread_callbacks, - const struct avc_lock_callback *lock_callbacks); + const struct avc_lock_callback *lock_callbacks) + __attribute__ ((deprecated("Use avc_open and selinux_set_callback")));/** * avc_open - Initialize the AVC.
Signature · 1 line
2.17.1
PATCH v2 13/18 avc: create internal avc_init interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that avc_init is marked deprecated, create an avc_init2 interface for internal users.
--- libselinux/src/avc.c | 11 ++++++++++- libselinux/src/avc_internal.h | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-)
libselinux/src/avc.c +10 -1
@@ -157,7 +157,7 @@ int avc_open(struct selinux_opt *opts, unsigned nopts)break ; } -return avc_init ("avc" ,NULL ,NULL ,NULL ,NULL ); +return avc_init2 ("avc" ,NULL ,NULL ,NULL ,NULL ); } int avc_init(const char *prefix,
@@ -165,6 +165,15 @@ int avc_init(const char *prefix,const struct avc_log_callback *log_cb, const struct avc_thread_callback *thread_cb, const struct avc_lock_callback *lock_cb) +{ + return avc_init2(prefix, mem_cb, log_cb, thread_cb, lock_cb); +} + +int avc_init2 (const char *prefix, +const struct avc_memory_callback *mem_cb, +const struct avc_log_callback *log_cb, +const struct avc_thread_callback *thread_cb, +const struct avc_lock_callback *lock_cb) {struct avc_node *new;int i, rc =0 ;
libselinux/src/avc_internal.h +5 -0
@@ -173,4 +173,9 @@ int avc_ss_set_auditdeny(security_id_t ssid, security_id_t tsid,/* netlink kernel message code */ extern int avc_netlink_trouble ; +extern int avc_init2 (const char *msgprefix, +const struct avc_memory_callback *mem_callbacks, +const struct avc_log_callback *log_callbacks, +const struct avc_thread_callback *thread_callbacks, +const struct avc_lock_callback *lock_callbacks);#endif /* _SELINUX_AVC_INTERNAL_H_ */
Signature · 1 line
2.17.1
PATCH v2 14/18 matchpathcon: create internal matchpathcon_fini interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that matchpathcon_fini is marked deprecated, create an matchpathcon_fini2 interface for internal users. We create a new header file for matchpathcon_internal interfaces.
--- libselinux/src/matchpathcon.c | 10 ++++++++-- libselinux/src/matchpathcon_internal.h | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 libselinux/src/matchpathcon_internal.h
libselinux/src/matchpathcon.c +8 -2
@@ -3,6 +3,7 @@#include <errno.h> #include <stdio.h> #include "selinux_internal.h" +#include "matchpathcon_internal.h" #include "label_internal.h" #include "callbacks.h" #include <limits.h>
@@ -317,7 +318,7 @@ void matchpathcon_filespec_destroy(void)static void matchpathcon_thread_destructor (void __attribute__((unused)) *ptr) { -matchpathcon_fini (); +matchpathcon_fini2 (); }void __attribute__((destructor))matchpathcon_lib_destructor (void );
@@ -357,7 +358,7 @@ int matchpathcon_init(const char *path)return matchpathcon_init_prefix (path,NULL ); } -void matchpathcon_fini (void ) +void matchpathcon_fini2 (void ) {free_array_elts ();
@@ -367,6 +368,11 @@ void matchpathcon_fini(void) } } +void matchpathcon_fini (void ) +{ +matchpathcon_fini2 (); +} +/* * We do not want to resolve a symlink to a real path if it is the final * component of the name. Thus we split the pathname on the last "/" and
libselinux/src/matchpathcon_internal.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef SRC_MATCHPATHCON_INTERNAL_H_ +#define SRC_MATCHPATHCON_INTERNAL_H_ + +void matchpathcon_fini2 (void ); + +#endif
Signature · 1 line
2.17.1
PATCH v2 15/18 matchpathcon: create internal matchpathcon interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that matchpathcon is marked deprecated, create an matchpathcon2 interface for internal users.
--- libselinux/src/matchpathcon.c | 8 ++++++-- libselinux/src/matchpathcon_internal.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)
libselinux/src/matchpathcon.c +6 -2
@@ -433,7 +433,11 @@ out:return rc; } -int matchpathcon (const char *path,mode_t mode,char ** con) +int matchpathcon (const char *path,mode_t mode,char ** con) { +return matchpathcon2 (path, mode, con); +} + +int matchpathcon2 (const char *path,mode_t mode,char ** con) {char stackpath[PATH_MAX +1 ];char *p =NULL ;
@@ -456,7 +460,7 @@ int matchpathcon(const char *path, mode_t mode, char ** con)int matchpathcon_index (const char *name,mode_t mode,char ** con) { -int i =matchpathcon (name, mode, con); +int i =matchpathcon2 (name, mode, con);if (i <0 )return -1 ;
libselinux/src/matchpathcon_internal.h +2 -0
@@ -3,4 +3,6 @@void matchpathcon_fini2 (void ); +int matchpathcon2 (const char *path,mode_t mode,char ** con); +#endif
Signature · 1 line
2.17.1
PATCH v2 16/18 selinux_check_passwd_access: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
Update the one internal tree caller in the same file to call selinux_check_passwd_access2.
--- libselinux/include/selinux/selinux.h | 4 +++- libselinux/src/checkAccess.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
libselinux/include/selinux/selinux.h +3 -1
@@ -609,7 +609,9 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ -extern int selinux_check_passwd_access (access_vector_t requested); +extern int selinux_check_passwd_access (access_vector_t requested) + __attribute__ ((deprecated ("Use selinux_check_access" ))); +extern int checkPasswdAccess (access_vector_t requested) __attribute__ ((deprecated ("Use selinux_check_access" )));
libselinux/src/checkAccess.c +5 -2
@@ -64,7 +64,7 @@ int selinux_check_access(const char *scon, const char *tcon, const char *class,return avc_has_perm (scon_id, tcon_id, sclass, av,NULL , aux); } -int selinux_check_passwd_access (access_vector_t requested) +static int selinux_check_passwd_access2 (access_vector_t requested) {int status =-1 ;char *user_context;
@@ -99,8 +99,11 @@ int selinux_check_passwd_access(access_vector_t requested)return status; } +int selinux_check_passwd_access (access_vector_t requested) { +return selinux_check_passwd_access2 (requested); +}int checkPasswdAccess (access_vector_t requested) { -return selinux_check_passwd_access (requested); +return selinux_check_passwd_access2 (requested); }
Signature · 1 line
2.17.1
PATCH v2 17/18 utils: matchpathcon to use interal interfaces
In reply to [email protected]From: William Roberts <[email protected]>
Not that the matchpathcon library interfaces are deprecated, matchpathcon needs to use the 2 variants and statically link.
--- libselinux/src/matchpathcon.c | 6 +++++- libselinux/src/matchpathcon_internal.h | 2 ++ libselinux/utils/Makefile | 6 ++++++ libselinux/utils/matchpathcon.c | 9 ++++++--- 4 files changed, 19 insertions(+), 4 deletions(-)
libselinux/src/matchpathcon.c +5 -1
@@ -352,10 +352,14 @@ int matchpathcon_init_prefix(const char *path, const char *subset)return hnd ?0 :-1 ; } +int matchpathcon_init2 (const char *path) +{ +return matchpathcon_init_prefix (path,NULL ); +}int matchpathcon_init (const char *path) { -return matchpathcon_init_prefix (path,NULL ); +return matchpathcon_init2 (path); }void matchpathcon_fini2 (void )
libselinux/src/matchpathcon_internal.h +2 -0
@@ -1,6 +1,8 @@#ifndef SRC_MATCHPATHCON_INTERNAL_H_ #define SRC_MATCHPATHCON_INTERNAL_H_ +int matchpathcon_init2 (const char *path); +void matchpathcon_fini2 (void );int matchpathcon2 (const char *path,mode_t mode,char ** con);
libselinux/utils/Makefile +6 -0
@@ -58,6 +58,12 @@ sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol sefcontext_compile: sefcontext_compile.o ../src/regex.o +matchpathcon: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a + +matchpathcon: CFLAGS += -I../src + +matchpathcon: matchpathcon.o ../src/regex.o + all: $(TARGETS) install: all
libselinux/utils/matchpathcon.c +6 -3
@@ -11,6 +11,9 @@#include <limits.h> #include <stdlib.h> +#include "matchpathcon_internal.h" + +static __attribute__ ((__noreturn__))void usage (const char *progname) { fprintf(stderr,
@@ -22,7 +25,7 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname)static int printmatchpathcon (const char *path,int header,int mode) {char *buf; -int rc =matchpathcon (path, mode, &buf); +int rc =matchpathcon2 (path, mode, &buf);if (rc <0 ) {if (errno ==ENOENT ) { buf =strdup ("<<none>>" );
@@ -103,7 +106,7 @@ int main(int argc, char **argv)exit (1 ); } init =1 ; -if (matchpathcon_init (optarg)) { +if (matchpathcon_init2 (optarg)) { fprintf(stderr, "Error while processing %s: %s\n", optarg,
@@ -195,6 +198,6 @@ int main(int argc, char **argv) error |=printmatchpathcon (path, header, mode); } } -matchpathcon_fini (); +matchpathcon_fini2 ();return error; }
Signature · 1 line
2.17.1
PATCH v2 18/18 utils: matchpathcon add deprecated warning
In reply to [email protected]From: William Roberts <[email protected]>
Add a deprecated warning to matchpathcon encouraging users to switch to selabel_lookup.
--- libselinux/utils/matchpathcon.c | 3 +++ 1 file changed, 3 insertions(+)
libselinux/utils/matchpathcon.c +3 -0
@@ -76,6 +76,9 @@ int main(int argc, char **argv)int error =0 ;int quiet =0 ; +fprintf (stderr, +"Deprecated, use selabel_lookup\n" ); +if (argc <2 )usage (argv[0 ]);
Signature · 1 line
2.17.1
Hello,
Does "make install && make install-pywrap" works for you? On both my development system (Arch Linux with swig 4.0.1) and Travis-CI
(https://travis-ci.org/github/fishilico/selinux/jobs/675842719), swig fails to build libselinux Python bindings (with your patches):
building 'selinux._selinux' extension
swigging selinuxswig_python.i to selinuxswig_python_wrap.c
swig -python -o selinuxswig_python_wrap.c selinuxswig_python.i ../include/selinux/avc.h:67: Error: Syntax error - possibly a missing semicolon.
error: command 'swig' failed with exit status 1
Makefile:133: recipe for target 'pywrap' failed
The problematic line is:
extern int sidget(security_id_t sid) __attribute__ ((deprecated));
It seems that swig does not understand this attribute.
Nicolas
Quoted 49 lines · On Thu, Apr 16, 2020 at 5:44 PM <[email protected]> wrote:
V2:
- Simplified now thatdso.hstuff has been removed.
-selinux_check_passwd_accesshas been deprecated and now bothselinux_check_passwd_accessand checkPasswdAccess are recomendingselinux_check_access.
- matchpathcon is linked statically to get access to deprecated routines and prints a deprecated warning to stderr.V1:
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared hereint foo(void) { ^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {[PATCH v2 01/18]
security_load_booleans: update return comment [PATCH v2 02/18]security_load_booleans: annotate deprecated [PATCH v2 03/18]selinux_booleans_path: annotate deprecated [PATCH v2 04/18]selinux_users_path: annotate deprecated [PATCH v2 05/18]rpm_execcon: annotate deprecated
[PATCH v2 06/18] sidget: annotate deprecated
[PATCH v2 07/18] sidput: annotate deprecated
[PATCH v2 08/18] checkPasswdAccess: annotate deprecated [PATCH v2 09/18]matchpathcon_init: annotate deprecated [PATCH v2 10/18]matchpathcon_fini: annotate deprecated [PATCH v2 11/18] matchpathcon: annotate deprecated
[PATCH v2 12/18]avc_init: annotate deprecated
[PATCH v2 13/18] avc: create internalavc_initinterface [PATCH v2 14/18] matchpathcon: create internalmatchpathcon_fini[PATCH v2 15/18] matchpathcon: create internal matchpathcon interface [PATCH v2 16/18]selinux_check_passwd_access: annotate deprecated [PATCH v2 17/18] utils: matchpathcon to use interal interfaces [PATCH v2 18/18] utils: matchpathcon add deprecated warning
Quoted 10 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nicolas Iooss
Sent: Sunday, April 19, 2020 8:47 AM
To: William Roberts <[email protected]>
Cc: SElinux list <[email protected]>
Subject: Re: Annotate Deprecated Functions in libselinux
Quoted 3 lines
Hello,
Does "make install && make install-pywrap" works for you? On both my
No because I didn't build the python bindings, I total forgot.
Quoted 11 lines
development system (Arch Linux with swig 4.0.1) and Travis-CI (https://travis-
ci.org/github/fishilico/selinux/jobs/675842719), swig fails to build libselinux Python bindings (with your patches):building 'selinux._selinux' extension
swigging selinuxswig_python.i toselinuxswig_python_wrap.cswig -python -oselinuxswig_python_wrap.cselinuxswig_python.i../include/selinux/avc.h:67: Error: Syntax error - possibly a missing semicolon.
error: command 'swig' failed with exit status 1
Makefile:133: recipe for target 'pywrap' failed
Quoted 5 lines
The problematic line is:
extern int
sidget(security_id_t sid)__attribute__((deprecated));It seems that swig does not understand this attribute.
Yeah, I agree with your triage of the issue. I think I'll have to define a DEPRECATED() macro and turn it off when SWIG is defined.
We also might even want to consider using:
https://pypi.org/project/Deprecated/
Quoted 51 lines
Nicolas
Quoted 47 lines · On Thu, Apr 16, 2020 at 5:44 PM <[email protected]> wrote:
V2:
- Simplified now thatdso.hstuff has been removed.
-selinux_check_passwd_accesshas been deprecated and now bothselinux_check_passwd_accessand checkPasswdAccess are recomendingselinux_check_access.
- matchpathcon is linked statically to get access to deprecated routines and prints a deprecated warning to stderr.V1:
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared hereint foo(void) { ^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {[PATCH v2 01/18]
security_load_booleans: update return comment [PATCH v2 02/18]security_load_booleans: annotate deprecated [PATCH v2 03/18]selinux_booleans_path: annotate deprecated [PATCH v2 04/18]selinux_users_path: annotate deprecated [PATCH v2 05/18]rpm_execcon:
annotate deprecated [PATCH v2 06/18] sidget: annotate deprecated [PATCH v2 07/18] sidput: annotate deprecated [PATCH v2 08/18]
checkPasswdAccess: annotate deprecated [PATCH v2 09/18]matchpathcon_init: annotate deprecated [PATCH v2 10/18]matchpathcon_fini: annotate deprecated [PATCH v2 11/18] matchpathcon:
annotate deprecated [PATCH v2 12/18]avc_init: annotate deprecated [PATCH v2 13/18] avc: create internalavc_initinterface [PATCH v2 14/18] matchpathcon: create internalmatchpathcon_fini[PATCH v2 15/18] matchpathcon: create internal matchpathcon interface [PATCH v2 16/18]selinux_check_passwd_access: annotate deprecated [PATCH v2 17/18] utils: matchpathcon to use interal interfaces [PATCH v2 18/18]
utils: matchpathcon add deprecated warning
PATCH v3 1/1 Annotate Deprecated Functions in libselinux
In reply to Nicolas IoossV3:
- Made the deprecated annotation dependent on __GNUC__ like the __format__(printf,...) specifiers. This will allow these not be defined when swig is building, so this will fix the swig syntax issues.
- Swig's build flags include -Wno-deprecated-declarations becuase the bindings need to pull the fill API out, even deprecated functions.
- Rather than compile matchpathcon with static selinux, I just set its compile flags to include -Wno-deprecated-declarations. Essentially saying, yes use this old interface it's Ok in this instance.
V2:
- Simplified now that dso.h stuff has been removed.
- selinux_check_passwd_access has been deprecated and now both selinux_check_passwd_access and checkPasswdAccess are recomending selinux_check_access.
- matchpathcon is linked statically to get access to deprecated routines and prints a deprecated warning to stderr.
V1:
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.
External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared here
int foo(void) {
^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {
[PATCH v3 01/19] security_load_booleans: update return comment [PATCH v3 02/19] security_load_booleans: annotate deprecated [PATCH v3 03/19] selinux_booleans_path: annotate deprecated [PATCH v3 04/19] selinux_users_path: annotate deprecated [PATCH v3 05/19] rpm_execcon: annotate deprecated
[PATCH v3 06/19] sidget: annotate deprecated
[PATCH v3 07/19] sidput: annotate deprecated
[PATCH v3 08/19] checkPasswdAccess: annotate deprecated [PATCH v3 09/19] matchpathcon_init: annotate deprecated [PATCH v3 10/19] matchpathcon_fini: annotate deprecated [PATCH v3 11/19] matchpathcon: annotate deprecated
[PATCH v3 12/19] avc_init: annotate deprecated
[PATCH v3 13/19] avc: create internal avc_init interface [PATCH v3 14/19] matchpathcon: create internal matchpathcon_fini [PATCH v3 15/19] matchpathcon: create internal matchpathcon interface [PATCH v3 16/19] selinux_check_passwd_access: annotate deprecated [PATCH v3 17/19] matchpathcon: allow use of deprecated routines [PATCH v3 18/19] utils: matchpathcon add deprecated warning [PATCH v3 19/19] Makefile: swig build allow deprecated functions
PATCH v3 1/19 security_load_booleans: update return comment
From: William Roberts <[email protected]>
The code returns -1 not 0, correct it.
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -323,7 +323,7 @@ extern int security_set_boolean_list(size_t boolcnt, SELboolean * boollist, int permanent);/* Load policy boolean settings. Deprecated as local policy booleans no -* longer supported. Will always return 0. +* longer supported. Will always return -1. */ extern int security_load_booleans (char *path);
Signature · 1 line
2.17.1
PATCH v3 2/19 security_load_booleans: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -325,7 +325,11 @@ extern int security_set_boolean_list(size_t boolcnt,/* Load policy boolean settings. Deprecated as local policy booleans no * longer supported. Will always return -1. */ -extern int security_load_booleans (char *path); +extern int security_load_booleans(char *path) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +;/* Check the validity of a security context. */ extern int security_check_context (const char * con);
Signature · 1 line
2.17.1
PATCH v3 3/19 selinux_booleans_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -579,7 +579,11 @@ extern const char *selinux_contexts_path(void);extern const char *selinux_securetty_types_path (void );extern const char *selinux_booleans_subs_path (void );/* Deprecated as local policy booleans no longer supported. */ -extern const char *selinux_booleans_path (void ); +extern const char *selinux_booleans_path (void ) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +;extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ extern const char *selinux_users_path (void );
Signature · 1 line
2.17.1
PATCH v3 4/19 selinux_users_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -586,7 +586,11 @@ __attribute__ ((deprecated)) ;extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ -extern const char *selinux_users_path (void ); +extern const char *selinux_users_path (void ) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +;extern const char *selinux_usersconf_path (void );extern const char *selinux_translations_path (void );extern const char *selinux_colors_path (void );
Signature · 1 line
2.17.1
PATCH v3 5/19 rpm_execcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -645,7 +645,11 @@ extern int setexecfilecon(const char *filename, const char *fallback_type);/* Execute a helper for rpm in an appropriate security context. */ extern int rpm_execcon(unsigned int verified, const char *filename, -char *const argv[],char *const envp[]); + char *const argv[], char *const envp[]) +#ifdef __GNUC__ + __attribute__((deprecated("Use setexecfilecon and execve"))) +#endif +;#endif /* Returns whether a file context is customizable, and should not
Signature · 1 line
2.17.1
PATCH v3 6/19 sidget: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +5 -1
@@ -64,7 +64,11 @@ extern int avc_context_to_sid_raw(const char * ctx, security_id_t * sid);* reference count). Note that avc_context_to_sid() also * increments reference counts. */ -extern int sidget (security_id_t sid); +extern int sidget(security_id_t sid) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +; /** * sidput - decrement SID reference counter.
Signature · 1 line
2.17.1
PATCH v3 7/19 sidput: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +5 -1
@@ -80,7 +80,11 @@ __attribute__ ((deprecated))* zero, the SID is invalid, and avc_context_to_sid() must * be called to obtain a new SID for the security context. */ -extern int sidput (security_id_t sid); +extern int sidput(security_id_t sid) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +; /** * avc_get_initial_sid - get SID for an initial kernel security identifier
Signature · 1 line
2.17.1
PATCH v3 8/19 checkPasswdAccess: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -619,7 +619,11 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ extern int selinux_check_passwd_access (access_vector_t requested); -extern int checkPasswdAccess (access_vector_t requested); +extern int checkPasswdAccess(access_vector_t requested) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selinux_check_access"))) +#endif +; /* Check if the tty_context is defined as a securetty Return 0 if secure, < 0 otherwise. */
Signature · 1 line
2.17.1
PATCH v3 9/19 matchpathcon_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -465,7 +465,11 @@ extern void set_matchpathcon_flags(unsigned int flags);function also checks for a 'path'.homedirs file and a 'path'.local file and loads additional specifications from them if present. */ -extern int matchpathcon_init (const char *path); +extern int matchpathcon_init(const char *path) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selabel_open with backend SELABEL_CTX_FILE"))) +#endif +; /* Same as matchpathcon_init, but only load entries with regexes that have stems that are prefixes of 'prefix'. */
Signature · 1 line
2.17.1
PATCH v3 10/19 matchpathcon_fini: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -476,7 +476,11 @@ extern int matchpathcon_init(const char *path)extern int matchpathcon_init_prefix (const char *path,const char *prefix);/* Free the memory allocated by matchpathcon_init. */ -extern void matchpathcon_fini (void ); +extern void matchpathcon_fini(void) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selabel_close"))) +#endif +; /* Resolve all of the symlinks and relative portions of a pathname, but NOT * the final component (same a realpath() unless the final component is a
Signature · 1 line
2.17.1
PATCH v3 11/19 matchpathcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -494,7 +494,11 @@ extern int realpath_not_final(const char *name, char *resolved_path);If matchpathcon_init has not already been called, then this function will call it upon its first invocation with a NULL path. */ extern int matchpathcon(const char *path, -mode_t mode,char ** con); + mode_t mode, char ** con) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selabel_lookup instead"))) +#endif +; /* Same as above, but return a specification index for later use in a matchpathcon_filespec_add() call - see below. */
Signature · 1 line
2.17.1
PATCH v3 12/19 avc_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +5 -1
@@ -200,7 +200,11 @@ extern int avc_init(const char *msgprefix, const struct avc_memory_callback *mem_callbacks, const struct avc_log_callback *log_callbacks, const struct avc_thread_callback *thread_callbacks, - const struct avc_lock_callback *lock_callbacks); + const struct avc_lock_callback *lock_callbacks) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use avc_open and selinux_set_callback"))) +#endif +;/** * avc_open - Initialize the AVC.
Signature · 1 line
2.17.1
PATCH v3 13/19 avc: create internal avc_init interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that avc_init is marked deprecated, create an avc_init2 interface for internal users.
--- libselinux/src/avc.c | 11 ++++++++++- libselinux/src/avc_internal.h | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-)
libselinux/src/avc.c +10 -1
@@ -157,7 +157,7 @@ int avc_open(struct selinux_opt *opts, unsigned nopts)break ; } -return avc_init ("avc" ,NULL ,NULL ,NULL ,NULL ); +return avc_init2 ("avc" ,NULL ,NULL ,NULL ,NULL ); } int avc_init(const char *prefix,
@@ -165,6 +165,15 @@ int avc_init(const char *prefix,const struct avc_log_callback *log_cb, const struct avc_thread_callback *thread_cb, const struct avc_lock_callback *lock_cb) +{ + return avc_init2(prefix, mem_cb, log_cb, thread_cb, lock_cb); +} + +int avc_init2 (const char *prefix, +const struct avc_memory_callback *mem_cb, +const struct avc_log_callback *log_cb, +const struct avc_thread_callback *thread_cb, +const struct avc_lock_callback *lock_cb) {struct avc_node *new;int i, rc =0 ;
libselinux/src/avc_internal.h +5 -0
@@ -173,4 +173,9 @@ int avc_ss_set_auditdeny(security_id_t ssid, security_id_t tsid,/* netlink kernel message code */ extern int avc_netlink_trouble ; +extern int avc_init2 (const char *msgprefix, +const struct avc_memory_callback *mem_callbacks, +const struct avc_log_callback *log_callbacks, +const struct avc_thread_callback *thread_callbacks, +const struct avc_lock_callback *lock_callbacks);#endif /* _SELINUX_AVC_INTERNAL_H_ */
Signature · 1 line
2.17.1
Re: [PATCH v3 13/19] avc: create internal avc_init interface
Quoted 56 lines · On Mon, Apr 20, 2020 at 5:46 PM <[email protected]> wrote:
From: William Roberts <[email protected]>
Now that
avc_initis marked deprecated, create anavc_init2interface for internal users.Signed-off-by William Roberts <[email protected]>--- libselinux/src/avc.c | 11 ++++++++++- libselinux/src/avc_internal.h | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-)libselinux/src/avc.c +10
-1@@ -157,7 +157,7 @@ int avc_open(struct selinux_opt *opts, unsigned nopts)break ; } -return avc_init ("avc" ,NULL ,NULL ,NULL ,NULL ); +return avc_init2 ("avc" ,NULL ,NULL ,NULL ,NULL ); } int avc_init(const char *prefix,@@ -165,6 +165,15 @@ int avc_init(const char *prefix,const struct avc_log_callback *log_cb, const struct avc_thread_callback *thread_cb, const struct avc_lock_callback *lock_cb) +{ + return avc_init2(prefix, mem_cb, log_cb, thread_cb, lock_cb); +} + +int avc_init2 (const char *prefix, +const struct avc_memory_callback *mem_cb, +const struct avc_log_callback *log_cb, +const struct avc_thread_callback *thread_cb, +const struct avc_lock_callback *lock_cb) {struct avc_node *new;int i, rc =0 ;libselinux/src/avc_internal.h +5
-1@@ -173,4 +173,9 @@ int avc_ss_set_auditdeny(security_id_t ssid, security_id_t tsid,/* netlink kernel message code */ extern int avc_netlink_trouble ; +extern int avc_init2 (const char *msgprefix, +const struct avc_memory_callback *mem_callbacks, +const struct avc_log_callback *log_callbacks, +const struct avc_thread_callback *thread_callbacks, +const struct avc_lock_callback *lock_callbacks);#endif /* _SELINUX_AVC_INTERNAL_H_ */ --
Quoted 1 line
2.17.1
Hello,
I do not see the point of having a new avc_init2() "internal interface". I get that avc_init() is deprecated, that avc_open() should be used, and that internally a new function (named avc_init2) is created to make the transition easier. But why is adding avc_init2() to avc_internal.h necessary? Which internal code is expected to use it?
If none, I would prefer to make avc_init2() static (changing this patch to "static init avc_init2(const char*msgprefix,", with a declaration before avc_open() if you do not want to move the function in the file).
I have the same question for matchpathcon_fini2(), matchpathcon2(), etc.
Moreover, I do not really like the "...2" naming (this is my own point of view and I won't block the patch because of it), because it seems to carry the meaning of "please now use this inferface", which is untrue. I suggest using avc_init_internal(), matchpathcon_fini_internal()... that do not carry such a meaning.
Thanks,
Nicolas
Re: [PATCH v3 13/19] avc: create internal avc_init interface
Quoted 51 lines · Nicolas Iooss
Quoted 49 lines · On Mon, Apr 20, 2020 at 5:46 PM <[email protected]> wrote:
From: William Roberts <[email protected]>
Now that
avc_initis marked deprecated, create anavc_init2interface for internal users.Signed-off-by William Roberts <[email protected]>--- libselinux/src/avc.c | 11 ++++++++++- libselinux/src/avc_internal.h | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-)libselinux/src/avc.c +10
-1@@ -157,7 +157,7 @@ int avc_open(struct selinux_opt *opts, unsigned nopts)break ; } -return avc_init ("avc" ,NULL ,NULL ,NULL ,NULL ); +return avc_init2 ("avc" ,NULL ,NULL ,NULL ,NULL ); } int avc_init(const char *prefix,@@ -165,6 +165,15 @@ int avc_init(const char *prefix,const struct avc_log_callback *log_cb, const struct avc_thread_callback *thread_cb, const struct avc_lock_callback *lock_cb) +{ + return avc_init2(prefix, mem_cb, log_cb, thread_cb, lock_cb); +} + +int avc_init2 (const char *prefix, +const struct avc_memory_callback *mem_cb, +const struct avc_log_callback *log_cb, +const struct avc_thread_callback *thread_cb, +const struct avc_lock_callback *lock_cb) {struct avc_node *new;int i, rc =0 ;libselinux/src/avc_internal.h +0
-0@@ -173,4 +173,9 @@ int avc_ss_set_auditdeny(security_id_t ssid, security_id_t tsid,/* netlink kernel message code */ extern int avc_netlink_trouble ;
Quoted 14 lines
Quoted 8 lines
libselinux/src/avc_internal.h +5
-1+extern int avc_init2 (const char *msgprefix, +const struct avc_memory_callback *mem_callbacks, +const struct avc_log_callback *log_callbacks, +const struct avc_thread_callback *thread_callbacks, +const struct avc_lock_callback *lock_callbacks);#endif /* _SELINUX_AVC_INTERNAL_H_ */ --2.17.1
Hello,
I do not see the point of having a newavc_init2()"internal interface". I get thatavc_init()is deprecated, thatavc_open()should be used, and that internally a new function (namedavc_init2) is created to make the transition easier. But why is adding
Its not just transition, its so internal callers can call into an interface that isn't marked
deprecated and we can keep the selinux build -Wdeprecated warning enabled.
Quoted 2 lines
avc_init2()toavc_internal.hnecessary? Which internal code is expected to use it?
Its not, it can be static in the file.
Quoted 6 lines
If none, I would prefer to make
avc_init2()static (changing this patch to "static init avc_init2(const char*msgprefix,", with a declaration beforeavc_open()if you do not want to move the function in the file).I have the same question for
matchpathcon_fini2(),matchpathcon2(), etc.
matchpathcon2
Quoted 6 lines
Moreover, I do not really like the "...2" naming (this is my own point of view and I won't block the patch because of it), because it seems to carry the meaning of "please now use this inferface", which is untrue. I suggest using
avc_init_internal(),matchpathcon_fini_internal()... that do not carry such a meaning.
Thats fine, I just picked one because it was the exact naming convention I used when discussing this with @sds. I didn't want to change that unless someone suggested it.
Quoted 4 lines
Thanks,
Nicolas
PATCH v3 14/19 matchpathcon: create internal matchpathcon_fini interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that matchpathcon_fini is marked deprecated, create an matchpathcon_fini2 interface for internal users. We create a new header file for matchpathcon_internal interfaces.
--- libselinux/src/matchpathcon.c | 10 ++++++++-- libselinux/src/matchpathcon_internal.h | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 libselinux/src/matchpathcon_internal.h
libselinux/src/matchpathcon.c +8 -2
@@ -3,6 +3,7 @@#include <errno.h> #include <stdio.h> #include "selinux_internal.h" +#include "matchpathcon_internal.h" #include "label_internal.h" #include "callbacks.h" #include <limits.h>
@@ -317,7 +318,7 @@ void matchpathcon_filespec_destroy(void)static void matchpathcon_thread_destructor (void __attribute__((unused)) *ptr) { -matchpathcon_fini (); +matchpathcon_fini2 (); }void __attribute__((destructor))matchpathcon_lib_destructor (void );
@@ -357,7 +358,7 @@ int matchpathcon_init(const char *path)return matchpathcon_init_prefix (path,NULL ); } -void matchpathcon_fini (void ) +void matchpathcon_fini2 (void ) {free_array_elts ();
@@ -367,6 +368,11 @@ void matchpathcon_fini(void) } } +void matchpathcon_fini (void ) +{ +matchpathcon_fini2 (); +} +/* * We do not want to resolve a symlink to a real path if it is the final * component of the name. Thus we split the pathname on the last "/" and
libselinux/src/matchpathcon_internal.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef SRC_MATCHPATHCON_INTERNAL_H_ +#define SRC_MATCHPATHCON_INTERNAL_H_ + +void matchpathcon_fini2 (void ); + +#endif
Signature · 1 line
2.17.1
PATCH v3 15/19 matchpathcon: create internal matchpathcon interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that matchpathcon is marked deprecated, create an matchpathcon2 interface for internal users.
--- libselinux/src/matchpathcon.c | 8 ++++++-- libselinux/src/matchpathcon_internal.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)
libselinux/src/matchpathcon.c +6 -2
@@ -433,7 +433,11 @@ out:return rc; } -int matchpathcon (const char *path,mode_t mode,char ** con) +int matchpathcon (const char *path,mode_t mode,char ** con) { +return matchpathcon2 (path, mode, con); +} + +int matchpathcon2 (const char *path,mode_t mode,char ** con) {char stackpath[PATH_MAX +1 ];char *p =NULL ;
@@ -456,7 +460,7 @@ int matchpathcon(const char *path, mode_t mode, char ** con)int matchpathcon_index (const char *name,mode_t mode,char ** con) { -int i =matchpathcon (name, mode, con); +int i =matchpathcon2 (name, mode, con);if (i <0 )return -1 ;
libselinux/src/matchpathcon_internal.h +2 -0
@@ -3,4 +3,6 @@void matchpathcon_fini2 (void ); +int matchpathcon2 (const char *path,mode_t mode,char ** con); +#endif
Signature · 1 line
2.17.1
PATCH v3 16/19 selinux_check_passwd_access: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
Update the one internal tree caller in the same file to call selinux_check_passwd_access2.
--- libselinux/include/selinux/selinux.h | 7 ++++++- libselinux/src/checkAccess.c | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-)
libselinux/include/selinux/selinux.h +6 -1
@@ -630,7 +630,12 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ -extern int selinux_check_passwd_access (access_vector_t requested); +extern int selinux_check_passwd_access(access_vector_t requested) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selinux_check_access"))) +#endif +; + extern int checkPasswdAccess(access_vector_t requested) #ifdef __GNUC__ __attribute__ ((deprecated("Use selinux_check_access")))
libselinux/src/checkAccess.c +5 -2
@@ -64,7 +64,7 @@ int selinux_check_access(const char *scon, const char *tcon, const char *class,return avc_has_perm (scon_id, tcon_id, sclass, av,NULL , aux); } -int selinux_check_passwd_access (access_vector_t requested) +static int selinux_check_passwd_access2 (access_vector_t requested) {int status =-1 ;char *user_context;
@@ -99,8 +99,11 @@ int selinux_check_passwd_access(access_vector_t requested)return status; } +int selinux_check_passwd_access (access_vector_t requested) { +return selinux_check_passwd_access2 (requested); +}int checkPasswdAccess (access_vector_t requested) { -return selinux_check_passwd_access (requested); +return selinux_check_passwd_access2 (requested); }
Signature · 1 line
2.17.1
PATCH v3 17/19 matchpathcon: allow use of deprecated routines
In reply to [email protected]From: William Roberts <[email protected]>
Utility matchpathcon uses the matchpathcon interface which has been deprectaed. However, this tool will continue to live on, so allow it to use the deprecated interface.
--- libselinux/utils/Makefile | 2 ++ 1 file changed, 2 insertions(+)
libselinux/utils/Makefile +2 -0
@@ -58,6 +58,8 @@ sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol sefcontext_compile: sefcontext_compile.o ../src/regex.o +matchpathcon: CFLAGS += -Wno-deprecated-declarations + all: $(TARGETS) install: all
Signature · 1 line
2.17.1
PATCH v3 18/19 utils: matchpathcon add deprecated warning
In reply to [email protected]From: William Roberts <[email protected]>
Add a deprecated warning to matchpathcon encouraging users to switch to selabel_lookup.
--- libselinux/utils/matchpathcon.c | 3 +++ 1 file changed, 3 insertions(+)
libselinux/utils/matchpathcon.c +3 -0
@@ -73,6 +73,9 @@ int main(int argc, char **argv)int error =0 ;int quiet =0 ; +fprintf (stderr, +"Deprecated, use selabel_lookup\n" ); +if (argc <2 )usage (argv[0 ]);
Signature · 1 line
2.17.1
PATCH v3 19/19 Makefile: swig build allow deprecated functions
In reply to [email protected]From: William Roberts <[email protected]>
The SWIG C build should allow deprecated functions and not warn on them because it is exposing the full interface including deprecated routines.
--- libselinux/src/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/src/Makefile +2 -1
@@ -105,7 +105,8 @@ FTS_LDLIBS ?= override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS) SWIG_CFLAGS += -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter \ - -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations + -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations \ + -Wno-deprecated-declarations RANLIB ?= ranlib
Signature · 1 line
2.17.1
PATCH v4 1/1 Annotate Deprecated Functions in libselinux
In reply to [email protected]V4:
- Drop the internal header interfaces, they were unused and pointless.
V3:
- Made the deprecated annotation dependent on __GNUC__ like the __format__(printf,...) specifiers. This will allow these not be defined when swig is building, so this will fix the swig syntax issues.
- Swig's build flags include -Wno-deprecated-declarations becuase the bindings need to pull the fill API out, even deprecated functions.
- Rather than compile matchpathcon with static selinux, I just set its compile flags to include -Wno-deprecated-declarations. Essentially saying, yes use this old interface it's Ok in this instance.
V2:
- Simplified now that dso.h stuff has been removed.
- selinux_check_passwd_access has been deprecated and now both selinux_check_passwd_access and checkPasswdAccess are recomending selinux_check_access.
- matchpathcon is linked statically to get access to deprecated routines and prints a deprecated warning to stderr.
V1:
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.
External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared here
int foo(void) {
^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {
[PATCH v4 01/18] security_load_booleans: update return comment [PATCH v4 02/18] security_load_booleans: annotate deprecated [PATCH v4 03/18] selinux_booleans_path: annotate deprecated [PATCH v4 04/18] selinux_users_path: annotate deprecated [PATCH v4 05/18] rpm_execcon: annotate deprecated [PATCH v4 06/18] sidget: annotate deprecated
[PATCH v4 07/18] sidput: annotate deprecated
[PATCH v4 08/18] checkPasswdAccess: annotate deprecated [PATCH v4 09/18] matchpathcon_init: annotate deprecated [PATCH v4 10/18] matchpathcon_fini: annotate deprecated [PATCH v4 11/18] matchpathcon: annotate deprecated [PATCH v4 12/18] avc_init: annotate deprecated
[PATCH v4 13/18] avc: create internal avc_init interface [PATCH v4 14/18] matchpathcon: create internal matchpathcon_fini [PATCH v4 15/18] selinux_check_passwd_access: annotate deprecated [PATCH v4 16/18] matchpathcon: allow use of deprecated routines [PATCH v4 17/18] utils: matchpathcon add deprecated warning [PATCH v4 18/18] Makefile: swig build allow deprecated functions
PATCH v4 1/18 security_load_booleans: update return comment
From: William Roberts <[email protected]>
The code returns -1 not 0, correct it.
--- libselinux/include/selinux/selinux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -1
@@ -323,7 +323,7 @@ extern int security_set_boolean_list(size_t boolcnt, SELboolean * boollist, int permanent);/* Load policy boolean settings. Deprecated as local policy booleans no -* longer supported. Will always return 0. +* longer supported. Will always return -1. */ extern int security_load_booleans (char *path);
Signature · 1 line
2.17.1
PATCH v4 2/18 security_load_booleans: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -325,7 +325,11 @@ extern int security_set_boolean_list(size_t boolcnt,/* Load policy boolean settings. Deprecated as local policy booleans no * longer supported. Will always return -1. */ -extern int security_load_booleans (char *path); +extern int security_load_booleans(char *path) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +;/* Check the validity of a security context. */ extern int security_check_context (const char * con);
Signature · 1 line
2.17.1
PATCH v4 3/18 selinux_booleans_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -579,7 +579,11 @@ extern const char *selinux_contexts_path(void);extern const char *selinux_securetty_types_path (void );extern const char *selinux_booleans_subs_path (void );/* Deprecated as local policy booleans no longer supported. */ -extern const char *selinux_booleans_path (void ); +extern const char *selinux_booleans_path (void ) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +;extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ extern const char *selinux_users_path (void );
Signature · 1 line
2.17.1
PATCH v4 4/18 selinux_users_path: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -586,7 +586,11 @@ __attribute__ ((deprecated)) ;extern const char *selinux_customizable_types_path (void );/* Deprecated as policy ./users no longer supported. */ -extern const char *selinux_users_path (void ); +extern const char *selinux_users_path (void ) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +;extern const char *selinux_usersconf_path (void );extern const char *selinux_translations_path (void );extern const char *selinux_colors_path (void );
Signature · 1 line
2.17.1
PATCH v4 5/18 rpm_execcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -645,7 +645,11 @@ extern int setexecfilecon(const char *filename, const char *fallback_type);/* Execute a helper for rpm in an appropriate security context. */ extern int rpm_execcon(unsigned int verified, const char *filename, -char *const argv[],char *const envp[]); + char *const argv[], char *const envp[]) +#ifdef __GNUC__ + __attribute__((deprecated("Use setexecfilecon and execve"))) +#endif +;#endif /* Returns whether a file context is customizable, and should not
Signature · 1 line
2.17.1
PATCH v4 6/18 sidget: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +5 -1
@@ -64,7 +64,11 @@ extern int avc_context_to_sid_raw(const char * ctx, security_id_t * sid);* reference count). Note that avc_context_to_sid() also * increments reference counts. */ -extern int sidget (security_id_t sid); +extern int sidget(security_id_t sid) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +; /** * sidput - decrement SID reference counter.
Signature · 1 line
2.17.1
PATCH v4 7/18 sidput: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +5 -1
@@ -80,7 +80,11 @@ __attribute__ ((deprecated))* zero, the SID is invalid, and avc_context_to_sid() must * be called to obtain a new SID for the security context. */ -extern int sidput (security_id_t sid); +extern int sidput(security_id_t sid) +#ifdef __GNUC__ +__attribute__ ((deprecated)) +#endif +; /** * avc_get_initial_sid - get SID for an initial kernel security identifier
Signature · 1 line
2.17.1
PATCH v4 8/18 checkPasswdAccess: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -619,7 +619,11 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ extern int selinux_check_passwd_access (access_vector_t requested); -extern int checkPasswdAccess (access_vector_t requested); +extern int checkPasswdAccess(access_vector_t requested) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selinux_check_access"))) +#endif +; /* Check if the tty_context is defined as a securetty Return 0 if secure, < 0 otherwise. */
Signature · 1 line
2.17.1
PATCH v4 9/18 matchpathcon_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -465,7 +465,11 @@ extern void set_matchpathcon_flags(unsigned int flags);function also checks for a 'path'.homedirs file and a 'path'.local file and loads additional specifications from them if present. */ -extern int matchpathcon_init (const char *path); +extern int matchpathcon_init(const char *path) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selabel_open with backend SELABEL_CTX_FILE"))) +#endif +; /* Same as matchpathcon_init, but only load entries with regexes that have stems that are prefixes of 'prefix'. */
Signature · 1 line
2.17.1
PATCH v4 10/18 matchpathcon_fini: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -476,7 +476,11 @@ extern int matchpathcon_init(const char *path)extern int matchpathcon_init_prefix (const char *path,const char *prefix);/* Free the memory allocated by matchpathcon_init. */ -extern void matchpathcon_fini (void ); +extern void matchpathcon_fini(void) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selabel_close"))) +#endif +; /* Resolve all of the symlinks and relative portions of a pathname, but NOT * the final component (same a realpath() unless the final component is a
Signature · 1 line
2.17.1
PATCH v4 11/18 matchpathcon: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/selinux.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +5 -1
@@ -494,7 +494,11 @@ extern int realpath_not_final(const char *name, char *resolved_path);If matchpathcon_init has not already been called, then this function will call it upon its first invocation with a NULL path. */ extern int matchpathcon(const char *path, -mode_t mode,char ** con); + mode_t mode, char ** con) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selabel_lookup instead"))) +#endif +; /* Same as above, but return a specification index for later use in a matchpathcon_filespec_add() call - see below. */
Signature · 1 line
2.17.1
PATCH v4 12/18 avc_init: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
--- libselinux/include/selinux/avc.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libselinux/include/selinux/avc.h +5 -1
@@ -200,7 +200,11 @@ extern int avc_init(const char *msgprefix, const struct avc_memory_callback *mem_callbacks, const struct avc_log_callback *log_callbacks, const struct avc_thread_callback *thread_callbacks, - const struct avc_lock_callback *lock_callbacks); + const struct avc_lock_callback *lock_callbacks) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use avc_open and selinux_set_callback"))) +#endif +;/** * avc_open - Initialize the AVC.
Signature · 1 line
2.17.1
PATCH v4 13/18 avc: create internal avc_init interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that avc_init is marked deprecated, create an avc_init2 interface for internal users.
--- libselinux/src/avc.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
libselinux/src/avc.c +25 -16
@@ -145,22 +145,7 @@ int avc_get_initial_sid(const char * name, security_id_t * sid)return rc; } -int avc_open (struct selinux_opt *opts,unsigned nopts) -{ - avc_setenforce =0 ; - -while (nopts--) -switch (opts[nopts].type) { -case AVC_OPT_SETENFORCE : - avc_setenforce =1 ; - avc_enforcing = !!opts[nopts].value; -break ; - } - -return avc_init ("avc" ,NULL ,NULL ,NULL ,NULL ); -} - -int avc_init(const char *prefix, +static int avc_init_internal(const char *prefix, const struct avc_memory_callback *mem_cb, const struct avc_log_callback *log_cb, const struct avc_thread_callback *thread_cb,
@@ -246,6 +231,30 @@ int avc_init(const char *prefix,return rc; } +int avc_open (struct selinux_opt *opts,unsigned nopts) +{ + avc_setenforce =0 ; + +while (nopts--) +switch (opts[nopts].type) { +case AVC_OPT_SETENFORCE : + avc_setenforce =1 ; + avc_enforcing = !!opts[nopts].value; +break ; + } + +return avc_init_internal ("avc" ,NULL ,NULL ,NULL ,NULL ); +} + +int avc_init (const char *prefix, +const struct avc_memory_callback *mem_cb, +const struct avc_log_callback *log_cb, +const struct avc_thread_callback *thread_cb, +const struct avc_lock_callback *lock_cb) +{ +return avc_init_internal (prefix, mem_cb, log_cb, thread_cb, lock_cb); +} +void avc_cache_stats (struct avc_cache_stats *p) {memcpy (p, &cache_stats,sizeof (cache_stats));
Signature · 1 line
2.17.1
PATCH v4 14/18 matchpathcon: create internal matchpathcon_fini interface
In reply to [email protected]From: William Roberts <[email protected]>
Now that matchpathcon_fini is marked deprecated, create an matchpathcon_fini2 interface for internal users. We create a new header file for matchpathcon_internal interfaces.
--- libselinux/src/matchpathcon.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
libselinux/src/matchpathcon.c +18 -9
@@ -315,9 +315,19 @@ void matchpathcon_filespec_destroy(void) fl_head =NULL ; } +static void matchpathcon_fini_internal (void ) +{ +free_array_elts (); + +if (hnd) { +selabel_close (hnd); + hnd =NULL ; + } +} +static void matchpathcon_thread_destructor (void __attribute__((unused)) *ptr) { -matchpathcon_fini (); +matchpathcon_fini_internal (); }void __attribute__((destructor))matchpathcon_lib_destructor (void );
@@ -359,12 +369,7 @@ int matchpathcon_init(const char *path)void matchpathcon_fini (void ) { -free_array_elts (); - -if (hnd) { -selabel_close (hnd); - hnd =NULL ; - } +matchpathcon_fini_internal (); }/*
@@ -427,7 +432,7 @@ out:return rc; } -int matchpathcon (const char *path,mode_t mode,char ** con) +static int matchpathcon_internal (const char *path,mode_t mode,char ** con) {char stackpath[PATH_MAX +1 ];char *p =NULL ;
@@ -448,9 +453,13 @@ int matchpathcon(const char *path, mode_t mode, char ** con)selabel_lookup (hnd, con, path, mode); } +int matchpathcon (const char *path,mode_t mode,char ** con) { +return matchpathcon_internal (path, mode, con); +} +int matchpathcon_index (const char *name,mode_t mode,char ** con) { -int i =matchpathcon (name, mode, con); +int i =matchpathcon_internal (name, mode, con);if (i <0 )return -1 ;
Signature · 1 line
2.17.1
PATCH v4 15/18 selinux_check_passwd_access: annotate deprecated
In reply to [email protected]From: William Roberts <[email protected]>
Update the one internal tree caller in the same file to call selinux_check_passwd_access2.
--- libselinux/include/selinux/selinux.h | 7 ++++++- libselinux/src/checkAccess.c | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-)
libselinux/include/selinux/selinux.h +6 -1
@@ -630,7 +630,12 @@ extern int selinux_check_access(const char * scon, const char * tcon, const char/* Check a permission in the passwd class. Return 0 if granted or -1 otherwise. */ -extern int selinux_check_passwd_access (access_vector_t requested); +extern int selinux_check_passwd_access(access_vector_t requested) +#ifdef __GNUC__ + __attribute__ ((deprecated("Use selinux_check_access"))) +#endif +; + extern int checkPasswdAccess(access_vector_t requested) #ifdef __GNUC__ __attribute__ ((deprecated("Use selinux_check_access")))
libselinux/src/checkAccess.c +5 -2
@@ -64,7 +64,7 @@ int selinux_check_access(const char *scon, const char *tcon, const char *class,return avc_has_perm (scon_id, tcon_id, sclass, av,NULL , aux); } -int selinux_check_passwd_access (access_vector_t requested) +static int selinux_check_passwd_access_internal (access_vector_t requested) {int status =-1 ;char *user_context;
@@ -99,8 +99,11 @@ int selinux_check_passwd_access(access_vector_t requested)return status; } +int selinux_check_passwd_access (access_vector_t requested) { +return selinux_check_passwd_access_internal (requested); +}int checkPasswdAccess (access_vector_t requested) { -return selinux_check_passwd_access (requested); +return selinux_check_passwd_access_internal (requested); }
Signature · 1 line
2.17.1
PATCH v4 16/18 matchpathcon: allow use of deprecated routines
In reply to [email protected]From: William Roberts <[email protected]>
Utility matchpathcon uses the matchpathcon interface which has been deprectaed. However, this tool will continue to live on, so allow it to use the deprecated interface.
--- libselinux/utils/Makefile | 2 ++ 1 file changed, 2 insertions(+)
libselinux/utils/Makefile +2 -0
@@ -56,6 +56,8 @@ sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol sefcontext_compile: sefcontext_compile.o ../src/regex.o +matchpathcon: CFLAGS += -Wno-deprecated-declarations + all: $(TARGETS) install: all
Signature · 1 line
2.17.1
PATCH v4 17/18 utils: matchpathcon add deprecated warning
In reply to [email protected]From: William Roberts <[email protected]>
Add a deprecated warning to matchpathcon encouraging users to switch to selabel_lookup.
--- libselinux/utils/matchpathcon.c | 3 +++ 1 file changed, 3 insertions(+)
libselinux/utils/matchpathcon.c +3 -0
@@ -73,6 +73,9 @@ int main(int argc, char **argv)int error =0 ;int quiet =0 ; +fprintf (stderr, +"Deprecated, use selabel_lookup\n" ); +if (argc <2 )usage (argv[0 ]);
Signature · 1 line
2.17.1
PATCH v4 18/18 Makefile: swig build allow deprecated functions
In reply to [email protected]From: William Roberts <[email protected]>
The SWIG C build should allow deprecated functions and not warn on them because it is exposing the full interface including deprecated routines.
--- libselinux/src/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/src/Makefile +2 -1
@@ -105,7 +105,8 @@ FTS_LDLIBS ?= override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS) SWIG_CFLAGS += -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter \ - -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations + -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations \ + -Wno-deprecated-declarations RANLIB ?= ranlib
Signature · 1 line
2.17.1
Quoted 54 lines · On Mon, Apr 27, 2020 at 10:23 PM <[email protected]> wrote:
V4:
- Drop the internal header interfaces, they were unused and pointless.V3:
- Made the deprecated annotation dependent on__GNUC__like the__format__(printf,...)specifiers. This will allow these not be defined when swig is building, so this will fix the swig syntax issues.
- Swig's build flags include -Wno-deprecated-declarations becuase the bindings need to pull the fill API out, even deprecated functions.
- Rather than compile matchpathcon with static selinux, I just set its compile flags to include -Wno-deprecated-declarations. Essentially saying, yes use this old interface it's Ok in this instance.V2:
- Simplified now thatdso.hstuff has been removed.
-selinux_check_passwd_accesshas been deprecated and now bothselinux_check_passwd_accessand checkPasswdAccess are recomendingselinux_check_access.
- matchpathcon is linked statically to get access to deprecated routines and prints a deprecated warning to stderr.V1:
I went through and annotated deprecated routines we have in libselinux that are mentioned to be deprecated either in code comments and/or manpages.External users, when compiling will see a warning similair to some sample output:
a.c: In function ‘main’:
a.c:18:2: warning: ‘foo’ is deprecated: foo bar msg [-Wdeprecated-declarations]
foo();
^~~
a.c:5:5: note: declared hereint foo(void) { ^~~a.c:19:2: warning: ‘boo’ is deprecated [-Wdeprecated-declarations]
boo();
^~~
a.c:11:5: note: declared here
int boo(void) {[PATCH v4 01/18]
security_load_booleans: update return comment [PATCH v4 02/18]security_load_booleans: annotate deprecated [PATCH v4 03/18]selinux_booleans_path: annotate deprecated [PATCH v4 04/18]selinux_users_path: annotate deprecated [PATCH v4 05/18]rpm_execcon: annotate deprecated [PATCH v4 06/18] sidget: annotate deprecated
[PATCH v4 07/18] sidput: annotate deprecated
[PATCH v4 08/18] checkPasswdAccess: annotate deprecated [PATCH v4 09/18]matchpathcon_init: annotate deprecated [PATCH v4 10/18]matchpathcon_fini: annotate deprecated
Quoted 8 lines
[PATCH v4 11/18] matchpathcon: annotate deprecated [PATCH v4 12/18]
avc_init: annotate deprecated
[PATCH v4 13/18] avc: create internalavc_initinterface [PATCH v4 14/18] matchpathcon: create internalmatchpathcon_fini[PATCH v4 15/18]selinux_check_passwd_access: annotate deprecated [PATCH v4 16/18] matchpathcon: allow use of deprecated routines [PATCH v4 17/18] utils: matchpathcon add deprecated warning [PATCH v4 18/18]Makefile: swig build allow deprecated functions
Hello,
Thanks for this v4. Some commit descriptions still use "...2" instead of "..._internal", but I do not think this needs to be fixed in another iteration, because the patches look otherwise good to me.
Feel free to apply them (eventually with fixed descriptions). Otherwise I will apply them tomorrow.
Nicolas