All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] libselinux:  fix getfilecon handling of zero-length context
@ 2007-07-09 16:45 Stephen Smalley
  2007-07-09 16:48 ` Joshua Brindle
  2007-07-09 18:07 ` getfilecon return code John D. Ramsdell
  0 siblings, 2 replies; 12+ messages in thread
From: Stephen Smalley @ 2007-07-09 16:45 UTC (permalink / raw)
  To: selinux; +Cc: Joshua Brindle, Karl MacMillan, John Ramsdell

As observed by John Ramsdell, *getfilecon() on a /proc/sys inode on
returns garbage and can lead to memory corruption upon later freecon.
This happens on 2.6.21 and later due to the proc sysctl rewrite in the
kernel.  The *getfilecon_raw() functions correctly return zero in this
case, but the non-raw functions are not handling that result properly.
Initialize *context on entry to *getfilecon() so that it has a
well-defined value even if *getfilecon_raw() returns zero.

Signed-off-by:  Stephen Smalley <sds@tycho.nsa.gov>

---

 libselinux/src/fgetfilecon.c |    2 ++
 libselinux/src/getfilecon.c  |    2 ++
 libselinux/src/lgetfilecon.c |    2 ++
 3 files changed, 6 insertions(+)

Index: trunk/libselinux/src/fgetfilecon.c
===================================================================
--- trunk/libselinux/src/fgetfilecon.c	(revision 2490)
+++ trunk/libselinux/src/fgetfilecon.c	(working copy)
@@ -51,6 +51,8 @@
 	security_context_t rcontext;
 	int ret;
 
+	*context = NULL;
+
 	ret = fgetfilecon_raw(fd, &rcontext);
 
 	if (ret > 0) {
Index: trunk/libselinux/src/lgetfilecon.c
===================================================================
--- trunk/libselinux/src/lgetfilecon.c	(revision 2490)
+++ trunk/libselinux/src/lgetfilecon.c	(working copy)
@@ -51,6 +51,8 @@
 	int ret;
 	security_context_t rcontext;
 
+	*context = NULL;
+
 	ret = lgetfilecon_raw(path, &rcontext);
 
 	if (ret > 0) {
Index: trunk/libselinux/src/getfilecon.c
===================================================================
--- trunk/libselinux/src/getfilecon.c	(revision 2490)
+++ trunk/libselinux/src/getfilecon.c	(working copy)
@@ -51,6 +51,8 @@
 	int ret;
 	security_context_t rcontext;
 
+	*context = NULL;
+
 	ret = getfilecon_raw(path, &rcontext);
 
 	if (ret > 0) {


-- 
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-09-12 15:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-09 16:45 [patch] libselinux: fix getfilecon handling of zero-length context Stephen Smalley
2007-07-09 16:48 ` Joshua Brindle
2007-07-09 16:50   ` Stephen Smalley
2007-07-09 17:39     ` Joshua Brindle
2007-07-09 18:07 ` getfilecon return code John D. Ramsdell
2007-07-09 18:30   ` Stephen Smalley
2007-07-09 18:42     ` Stephen Smalley
2007-07-09 19:13       ` Joshua Brindle
2007-07-10 12:41         ` Stephen Smalley
2007-07-10 17:49           ` Joshua Brindle
2007-09-12 15:43       ` Stephen Smalley
2007-07-09 20:01     ` John D. Ramsdell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.