libselinux: Verify context input to funtions to make sure the context field is not null.
PATCH 1/1 libselinux: Verify context input to funtions to make sure the context field is not null.
From: Dan Walsh <[email protected]>
Return errno EINVAL, to prevent segfault.
--- libselinux/src/avc_sidtab.c | 5 +++++ libselinux/src/canonicalize_context.c | 5 +++++ libselinux/src/check_context.c | 5 +++++ libselinux/src/compute_av.c | 5 +++++ libselinux/src/compute_create.c | 5 +++++ libselinux/src/compute_member.c | 5 +++++ libselinux/src/compute_relabel.c | 5 +++++ libselinux/src/compute_user.c | 5 +++++ libselinux/src/fsetfilecon.c | 8 ++++++-- libselinux/src/lsetfilecon.c | 9 +++++++-- libselinux/src/setfilecon.c | 8 ++++++-- 11 files changed, 59 insertions(+), 6 deletions(-)
libselinux/src/avc_sidtab.c +5 -0
@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,int hvalue, rc =0 ;struct sidtab_node *cur; +if (! ctx) { + errno =EINVAL ; +return -1 ; + } + *sid =NULL ; hvalue =sidtab_hash (ctx);
libselinux/src/canonicalize_context.c +5 -0
@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,size_t size;int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;
libselinux/src/check_context.c +5 -0
@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)char path[PATH_MAX ];int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;
libselinux/src/compute_av.c +5 -0
@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/access" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )
libselinux/src/compute_create.c +5 -0
@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/create" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )
libselinux/src/compute_member.c +5 -0
@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/member" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )
libselinux/src/compute_relabel.c +5 -0
@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/relabel" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )
libselinux/src/compute_user.c +5 -0
@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,return -1 ; } +if (! scon) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/user" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )
libselinux/src/fsetfilecon.c +6 -2
@@ -9,8 +9,12 @@int fsetfilecon_raw (int fd,const char * context) { -int rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;
libselinux/src/lsetfilecon.c +7 -2
@@ -9,8 +9,13 @@int lsetfilecon_raw (const char *path,const char * context) { -int rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + + rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;
libselinux/src/setfilecon.c +6 -2
@@ -9,8 +9,12 @@int setfilecon_raw (const char *path,const char * context) { -int rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;
Signature · 1 line
2.6.3
I believe this patch, or something similar, was sent to the list in the past and was rejected. Passing in a NULL context is considered invalid use, similar to strdup/strcmp/etc. and is a bug in the calling process.
Quoted 206 lines · Petr Lautrbach
From: Dan Walsh <[email protected]>
Return errno EINVAL, to prevent segfault.
Signed-off-by Petr Lautrbach <[email protected]>--- libselinux/src/avc_sidtab.c | 5 +++++ libselinux/src/canonicalize_context.c | 5 +++++ libselinux/src/check_context.c | 5 +++++ libselinux/src/compute_av.c | 5 +++++ libselinux/src/compute_create.c | 5 +++++ libselinux/src/compute_member.c | 5 +++++ libselinux/src/compute_relabel.c | 5 +++++ libselinux/src/compute_user.c | 5 +++++ libselinux/src/fsetfilecon.c | 8 ++++++-- libselinux/src/lsetfilecon.c | 9 +++++++-- libselinux/src/setfilecon.c | 8 ++++++-- 11 files changed, 59 insertions(+), 6 deletions(-)libselinux/src/avc_sidtab.c +5
-0@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,int hvalue, rc =0 ;struct sidtab_node *cur; +if (! ctx) { + errno =EINVAL ; +return -1 ; + } + *sid =NULL ; hvalue =sidtab_hash (ctx);libselinux/src/canonicalize_context.c +5
-0@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,size_t size;int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;libselinux/src/check_context.c +5
-0@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)char path[PATH_MAX ];int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;libselinux/src/compute_av.c +5
-0@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/access" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_create.c +5
-0@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/create" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_member.c +5
-0@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/member" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_relabel.c +5
-0@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/relabel" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_user.c +5
-0@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,return -1 ; } +if (! scon) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/user" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/fsetfilecon.c +6
-2@@ -9,8 +9,12 @@int fsetfilecon_raw (int fd,const char * context) { -int rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;libselinux/src/lsetfilecon.c +7
-2@@ -9,8 +9,13 @@int lsetfilecon_raw (const char *path,const char * context) { -int rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + + rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;libselinux/src/setfilecon.c +6
-2@@ -9,8 +9,12 @@int setfilecon_raw (const char *path,const char * context) { -int rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;
Quoted 3 lines · Steve Lawrence
I believe this patch, or something similar, was sent to the list in the past and was rejected. Passing in a NULL context is considered invalid use, similar to strdup/strcmp/etc. and is a bug in the calling process.
I didn't know that, sorry.
I'll mark this patch as upstream rejected, Fedora downstream only; to prevent future attempts to re-send it again.
Thanks,
Petr
Quoted 209 lines · Petr Lautrbach
Quoted 206 lines
From: Dan Walsh <[email protected]>
Return errno EINVAL, to prevent segfault.
Signed-off-by Petr Lautrbach <[email protected]>--- libselinux/src/avc_sidtab.c | 5 +++++ libselinux/src/canonicalize_context.c | 5 +++++ libselinux/src/check_context.c | 5 +++++ libselinux/src/compute_av.c | 5 +++++ libselinux/src/compute_create.c | 5 +++++ libselinux/src/compute_member.c | 5 +++++ libselinux/src/compute_relabel.c | 5 +++++ libselinux/src/compute_user.c | 5 +++++ libselinux/src/fsetfilecon.c | 8 ++++++-- libselinux/src/lsetfilecon.c | 9 +++++++-- libselinux/src/setfilecon.c | 8 ++++++-- 11 files changed, 59 insertions(+), 6 deletions(-)libselinux/src/avc_sidtab.c +5
-0@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,int hvalue, rc =0 ;struct sidtab_node *cur; +if (! ctx) { + errno =EINVAL ; +return -1 ; + } + *sid =NULL ; hvalue =sidtab_hash (ctx);libselinux/src/canonicalize_context.c +5
-0@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,size_t size;int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;libselinux/src/check_context.c +5
-0@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)char path[PATH_MAX ];int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;libselinux/src/compute_av.c +5
-0@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/access" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_create.c +5
-0@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/create" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_member.c +5
-0@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/member" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_relabel.c +5
-0@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/relabel" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/compute_user.c +5
-0@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,return -1 ; } +if (! scon) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/user" , selinux_mnt); fd =open (path,O_RDWR );if (fd <0 )libselinux/src/fsetfilecon.c +6
-2@@ -9,8 +9,12 @@int fsetfilecon_raw (int fd,const char * context) { -int rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;libselinux/src/lsetfilecon.c +7
-2@@ -9,8 +9,13 @@int lsetfilecon_raw (const char *path,const char * context) { -int rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + + rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;libselinux/src/setfilecon.c +6
-2@@ -9,8 +9,12 @@int setfilecon_raw (const char *path,const char * context) { -int rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc <0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;
Quoted 4 lines · Steve Lawrence
I believe this patch, or something similar, was sent to the list in the past and was rejected. Passing in a NULL context is considered invalid use, similar to strdup/strcmp/etc. and is a bug in the calling process.
It isn't unreasonable for an API to indicate invalid usage (which is what EINVAL does). The argument that strdup lets you shoot yourself in the foot so we should to isn't very compelling...
Quoted 213 lines · Petr Lautrbach
Quoted 196 lines
From: Dan Walsh<[email protected]>
Return errno EINVAL, to prevent segfault.
Signed-off-by Petr Lautrbach<[email protected]>--- libselinux/src/avc_sidtab.c | 5 +++++ libselinux/src/canonicalize_context.c | 5 +++++ libselinux/src/check_context.c | 5 +++++ libselinux/src/compute_av.c | 5 +++++ libselinux/src/compute_create.c | 5 +++++ libselinux/src/compute_member.c | 5 +++++ libselinux/src/compute_relabel.c | 5 +++++ libselinux/src/compute_user.c | 5 +++++ libselinux/src/fsetfilecon.c | 8 ++++++-- libselinux/src/lsetfilecon.c | 9 +++++++-- libselinux/src/setfilecon.c | 8 ++++++-- 11 files changed, 59 insertions(+), 6 deletions(-)libselinux/src/avc_sidtab.c +5
-0@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,int hvalue, rc =0 ;struct sidtab_node *cur; +if (! ctx) { + errno =EINVAL ; +return -1 ; + } + *sid =NULL ; hvalue =sidtab_hash (ctx);libselinux/src/canonicalize_context.c +5
-0@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,size_t size;int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;libselinux/src/check_context.c +5
-0@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)char path[PATH_MAX ];int fd, ret; +if (! con) { + errno =EINVAL ; +return -1 ; + } +if (!selinux_mnt) { errno =ENOENT ;return -1 ;libselinux/src/compute_av.c +5
-0@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/access" , selinux_mnt); fd =open (path,O_RDWR );if (fd<0 )libselinux/src/compute_create.c +5
-0@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/create" , selinux_mnt); fd =open (path,O_RDWR );if (fd<0 )libselinux/src/compute_member.c +5
-0@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/member" , selinux_mnt); fd =open (path,O_RDWR );if (fd<0 )libselinux/src/compute_relabel.c +5
-0@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,return -1 ; } +if ((! scon) || (! tcon)) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/relabel" , selinux_mnt); fd =open (path,O_RDWR );if (fd<0 )libselinux/src/compute_user.c +5
-0@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,return -1 ; } +if (! scon) { + errno =EINVAL ; +return -1 ; + } +snprintf (path,sizeof path,"%s/user" , selinux_mnt); fd =open (path,O_RDWR );if (fd<0 )libselinux/src/fsetfilecon.c +6
-2@@ -9,8 +9,12 @@int fsetfilecon_raw (int fd,const char * context) { -int rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =fsetxattr (fd,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc<0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;libselinux/src/lsetfilecon.c +7
-2@@ -9,8 +9,13 @@int lsetfilecon_raw (const char *path,const char * context) { -int rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 , -0 ); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + + rc =lsetxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc<0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;libselinux/src/setfilecon.c +0
-1@@ -9,8 +9,12 @@int setfilecon_raw (const char *path,const char * context) { - int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,libselinux/src/setfilecon.c line 20
Quoted 10 lines
libselinux/src/setfilecon.c +6
-1- 0); +int rc; +if (! context) { + errno =EINVAL ; +return -1 ; + } + rc =setxattr (path,XATTR_NAME_SELINUX , context,strlen (context) +1 ,0 );if (rc<0 && errno ==ENOTSUP ) {char * ccontext =NULL ;int err = errno;_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].