Skip to contentSkip to conversation

libselinux: update const qualifier of parameters in man pages

PATCH In review Christian Göttsche 2 participants 5 messages Dec 11, 2023 – Dec 12, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 libselinux: update const qualifier of parameters in man pages

Add missing const qualifier to parameters in the man pages to align them with <selinux/selinux.h>.

---
 libselinux/man/man3/getexeccon.3          |  4 +--
 libselinux/man/man3/security_compute_av.3 | 32 +++++++++++------------
 2 files changed, 18 insertions(+), 18 deletions(-)
libselinux/man/man3/getexeccon.3 +2 -2
index d6222a4f..9cc24e8c 100644
@@ -11,9 +11,9 @@ rpm_execcon \- run a helper for rpm in an appropriate security context
 .sp
 .BI "int getexeccon_raw(char **" context );
 .sp
-.BI "int setexeccon(char *" context );
+.BI "int setexeccon(const char *" context );
 .sp
-.BI "int setexeccon_raw(char *" context );
+.BI "int setexeccon_raw(const char *" context );
 .sp
 .BI "int setexecfilecon(const char *" filename ", const char *" fallback_type );
 .sp
libselinux/man/man3/security_compute_av.3 +16 -16
index efa4baf3..6c82eca5 100644
@@ -7,37 +7,37 @@ the SELinux policy database in the kernel
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.BI "int security_compute_av(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_flags(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_flags(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_flags_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_flags_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_create(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_create(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_create_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_create_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_create_name(char *" scon ", char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
+.BI "int security_compute_create_name(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
 .sp
-.BI "int security_compute_create_name_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
+.BI "int security_compute_create_name_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
 .sp
-.BI "int security_compute_relabel(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_relabel(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_relabel_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_relabel_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_member(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_member(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_member_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_member_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_user(char *" scon ", const char *" username ", char ***" con );
+.BI "int security_compute_user(const char *" scon ", const char *" username ", char ***" con );
 .sp
-.BI "int security_compute_user_raw(char *" scon ", const char *" username ", char ***" con );
+.BI "int security_compute_user_raw(const char *" scon ", const char *" username ", char ***" con );
 .sp
-.BI "int security_validatetrans(char *" scon ", const char *" tcon ", security_class_t "tclass ", char *" newcon );
+.BI "int security_validatetrans(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" newcon );
 .sp
-.BI "int security_validatetrans_raw(char *" scon ", const char *" tcon ", security_class_t "tclass ", char *" newcon );
+.BI "int security_validatetrans_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" newcon );
 .sp
 .BI "int security_get_initial_context(const char *" name ", char **" con );
 .sp
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 libselinux: always set errno on context translation failure

Allow callers to expect errno is set on failure, e.g. other exported libselinux functions like setexecfilecon(3).

---
 libselinux/src/setrans_client.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
libselinux/src/setrans_client.c +19 -3
index 920f9032..d7dbc0ca 100644
@@ -92,8 +92,10 @@ send_request(int fd, uint32_t function, const char *data1, const char *data2)
 	ssize_t count, expected;
 	unsigned int i;
 
-	if (fd < 0)
+	if (fd < 0) {
+		errno = EINVAL;
 		return -1;
+	}
 
 	if (!data1)
 		data1 = "";
@@ -123,8 +125,12 @@ send_request(int fd, uint32_t function, const char *data1, const char *data2)
 
 	while (((count = sendmsg(fd, &msgh, MSG_NOSIGNAL)) < 0)
 	       && (errno == EINTR)) ;
-	if (count < 0 || count != expected)
+	if (count < 0)
+		return -1;
+	if (count != expected) {
+		errno = EBADMSG;
 		return -1;
+	}
 
 	return 0;
 }
@@ -140,8 +146,10 @@ receive_response(int fd, uint32_t function, char **outdata, int32_t * ret_val)
 	struct iovec resp_data;
 	ssize_t count;
 
-	if (fd < 0)
+	if (fd < 0) {
+		errno = EINVAL;
 		return -1;
+	}
 
 	resp_hdr[0].iov_base = &func;
 	resp_hdr[0].iov_len = sizeof(func);
@@ -151,11 +159,17 @@ receive_response(int fd, uint32_t function, char **outdata, int32_t * ret_val)
 	resp_hdr[2].iov_len = sizeof(*ret_val);
 
 	while (((count = readv(fd, resp_hdr, 3)) < 0) && (errno == EINTR)) ;
+	if (count < 0) {
+		return -1;
+	}
+
 	if (count != (sizeof(func) + sizeof(data_size) + sizeof(*ret_val))) {
+		errno = EBADMSG;
 		return -1;
 	}
 
 	if (func != function || !data_size || data_size > MAX_DATA_BUF) {
+		errno = EBADMSG;
 		return -1;
 	}
 
@@ -172,6 +186,8 @@ receive_response(int fd, uint32_t function, char **outdata, int32_t * ret_val)
 	if (count < 0 || (uint32_t) count != data_size ||
 	    data[data_size - 1] != '\0') {
 		free(data);
+		if (count >= 0)
+			errno = EBADMSG;
 		return -1;
 	}
 	*outdata = data;
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/3 libselinux: state setexecfilecon(3) sets errno on failure

In reply to Christian Göttsche

The other functions (getexeccon(3) and setexeccon(3)) from the man page also set errno on failure similar to the getcon(3) function family.

---
 libselinux/man/man3/getexeccon.3 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libselinux/man/man3/getexeccon.3 +3 -1
index 9cc24e8c..edaa6669 100644
@@ -89,7 +89,9 @@ then executes the specified filename with the provided argument and
 environment arrays.
 .
 .SH "RETURN VALUE"
-On error \-1 is returned.
+On failure, \-1 is returned and
+.I errno
+is  set appropriately.
 
 On success
 .BR getexeccon (),
Signature · 1 line
2.43.0
Acked-by on v1 1/3
#3 lore raw
In reply to Christian Göttsche
Quoted 5 lines · Christian Göttsche

Add missing const qualifier to parameters in the man pages to align them with <selinux/selinux.h>.

For these three patches:

Quoted 83 lines
---
 libselinux/man/man3/getexeccon.3          |  4 +--
 libselinux/man/man3/security_compute_av.3 | 32 +++++++++++------------
 2 files changed, 18 insertions(+), 18 deletions(-)
libselinux/man/man3/getexeccon.3 +2 -2
index d6222a4f..9cc24e8c 100644
@@ -11,9 +11,9 @@ rpm_execcon \- run a helper for rpm in an appropriate security context
 .sp
 .BI "int getexeccon_raw(char **" context );
 .sp
-.BI "int setexeccon(char *" context );
+.BI "int setexeccon(const char *" context );
 .sp
-.BI "int setexeccon_raw(char *" context );
+.BI "int setexeccon_raw(const char *" context );
 .sp
 .BI "int setexecfilecon(const char *" filename ", const char *" fallback_type );
 .sp
libselinux/man/man3/security_compute_av.3 +16 -17
index efa4baf3..6c82eca5 100644
@@ -7,37 +7,37 @@ the SELinux policy database in the kernel
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.BI "int security_compute_av(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_flags(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_flags(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_flags_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_flags_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_create(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_create(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_create_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_create_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_create_name(char *" scon ", char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
+.BI "int security_compute_create_name(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
 .sp
-.BI "int security_compute_create_name_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
+.BI "int security_compute_create_name_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
 .sp
-.BI "int security_compute_relabel(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_relabel(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_relabel_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_relabel_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_member(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_member(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_member_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_member_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_user(char *" scon ", const char *" username ", char ***" con );
+.BI "int security_compute_user(const char *" scon ", const char *" username ", char ***" con );
 .sp
-.BI "int security_compute_user_raw(char *" scon ", const char *" username ", char ***" con );
+.BI "int security_compute_user_raw(const char *" scon ", const char *" username ", char ***" con );
 .sp
-.BI "int security_validatetrans(char *" scon ", const char *" tcon ", security_class_t "tclass ", char *" newcon );
+.BI "int security_validatetrans(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" newcon );
 .sp
-.BI "int security_validatetrans_raw(char *" scon ", const char *" tcon ", security_class_t "tclass ", char *" newcon );
+.BI "int security_validatetrans_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" newcon );
 .sp
 .BI "int security_get_initial_context(const char *" name ", char **" con );
 .sp
--

2.43.0

#4 lore raw
Quoted 4 lines · James Carter
Quoted 1 line · Christian Göttsche
Quoted 8 lines
Quoted 4 lines

Add missing const qualifier to parameters in the man pages to align them with <selinux/selinux.h>.

For these three patches:

These three patches have been merged.
Thanks,
Jim

Quoted 83 lines
Quoted 83 lines
---
 libselinux/man/man3/getexeccon.3          |  4 +--
 libselinux/man/man3/security_compute_av.3 | 32 +++++++++++------------
 2 files changed, 18 insertions(+), 18 deletions(-)
libselinux/man/man3/getexeccon.3 +2 -2
index d6222a4f..9cc24e8c 100644
@@ -11,9 +11,9 @@ rpm_execcon \- run a helper for rpm in an appropriate security context
 .sp
 .BI "int getexeccon_raw(char **" context );
 .sp
-.BI "int setexeccon(char *" context );
+.BI "int setexeccon(const char *" context );
 .sp
-.BI "int setexeccon_raw(char *" context );
+.BI "int setexeccon_raw(const char *" context );
 .sp
 .BI "int setexecfilecon(const char *" filename ", const char *" fallback_type );
 .sp
libselinux/man/man3/security_compute_av.3 +16 -17
index efa4baf3..6c82eca5 100644
@@ -7,37 +7,37 @@ the SELinux policy database in the kernel
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.BI "int security_compute_av(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_flags(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_flags(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_av_flags_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.BI "int security_compute_av_flags_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
-.BI "int security_compute_create(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_create(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_create_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_create_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_create_name(char *" scon ", char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
+.BI "int security_compute_create_name(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
 .sp
-.BI "int security_compute_create_name_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
+.BI "int security_compute_create_name_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" objname ", char **" newcon );
 .sp
-.BI "int security_compute_relabel(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_relabel(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_relabel_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_relabel_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_member(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_member(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_member_raw(char *" scon ", char *" tcon ", security_class_t "tclass ", char **" newcon );
+.BI "int security_compute_member_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", char **" newcon );
 .sp
-.BI "int security_compute_user(char *" scon ", const char *" username ", char ***" con );
+.BI "int security_compute_user(const char *" scon ", const char *" username ", char ***" con );
 .sp
-.BI "int security_compute_user_raw(char *" scon ", const char *" username ", char ***" con );
+.BI "int security_compute_user_raw(const char *" scon ", const char *" username ", char ***" con );
 .sp
-.BI "int security_validatetrans(char *" scon ", const char *" tcon ", security_class_t "tclass ", char *" newcon );
+.BI "int security_validatetrans(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" newcon );
 .sp
-.BI "int security_validatetrans_raw(char *" scon ", const char *" tcon ", security_class_t "tclass ", char *" newcon );
+.BI "int security_validatetrans_raw(const char *" scon ", const char *" tcon ", security_class_t "tclass ", const char *" newcon );
 .sp
 .BI "int security_get_initial_context(const char *" name ", char **" con );
 .sp
--

2.43.0