Skip to contentSkip to conversation

Patch to fix Pax/Grsecurity Problems

DISCUSSION Stephen Cook 3 participants 4 messages Jan 23, 2004 – Jan 26, 2004

lore
Share & tools
lore
#0 lore raw

I hope I don't sound to persistent but I am just wondering when this patch is going to be merged or if there is anything I can do to help speed it up. Such as any changes to the patch etc.

Thanks
Stephen
--

--------- Original Message ---------

DATE: Mon, 12 Jan 2004 15:03:54
From: Takashi Iwai <[email protected]>
To: [email protected]
Cc:

Quoted 89 lines

At Mon, 12 Jan 2004 12:27:23 +1100,

Quoted 9 lines · Stephen Cook

[1 <text/plain; us-ascii (7bit)>]
As you may be currently aware alsa-lib (libasound) does not work very well when using it under a kernel that has the Pax (http://pax.grsecurity.net) or Grsecurity (http://www.grsecurity.net) Patch.

The problem is because there is a function in a function (trampoline) - So gcc generates code that conflicts with pax. Also there is a text-relocation problem.

So I helped create patch that will fix these problems so alsa will be more usable on a Pax/Grsecurity machine (no chpax work arounds and more security). Currently this patch is included in alsa-lib-1.0.1 in Gentoo so it is undergoing large scale testing. For my part I have 2 machines running with Pax and this alsa-lib patch and I have had no problems :)

The code is a work around so if you know of a better way to do it please tell me.

i think this funciton-in-function is too dependent on gcc, too, and would like to get rid of it. the patch looks fine for me. or, we can add ifdef if someone still wants to keep the original style.

comments?

Takashi

Quoted 56 lines

____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005
[2 alsa-lib-1.0.1-notextrel-notrampoline.patch <text/plain; us-ascii (7bit)>]
diff -Nru alsa-lib-1.0.0rc2-original/src/control/hcontrol.c alsa-lib-1.0.0rc2/src/control/hcontrol.c

src/control/hcontrol.c +15 -5
@@ -48,6 +48,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <pthread.h>
 #ifndef DOC_HIDDEN
 #define __USE_GNU
 #endif
@@ -409,17 +410,26 @@
 	return 0;
 }
 
+static snd_hctl_t *compare_hctl;
+static int hctl_compare(const void *a, const void *b) {
+	return compare_hctl->compare(*(const snd_hctl_elem_t * const *) a,
+			     *(const snd_hctl_elem_t * const *) b);
+}
+
 static void snd_hctl_sort(snd_hctl_t *hctl)
 {
 	unsigned int k;
-	int compar(const void *a, const void *b) {
-		return hctl->compare(*(const snd_hctl_elem_t * const *) a,
-				     *(const snd_hctl_elem_t * const *) b);
-	}
+	static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER;
+
 	assert(hctl);
 	assert(hctl->compare);
 	INIT_LIST_HEAD(&hctl->elems);
-	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), compar);
+
+	pthread_mutex_lock(&sync_lock);
+	compare_hctl = hctl;
+	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), hctl_compare);
+	pthread_mutex_unlock(&sync_lock);
+
 	for (k = 0; k < hctl->count; k++)
 		list_add_tail(&hctl->pelems[k]->list, &hctl->elems);
 }

diff -Nru alsa-lib-1.0.0rc2-original/src/pcm/pcm_direct.c alsa-lib-1.0.0rc2/src/pcm/pcm_direct.c

src/pcm/pcm_direct.c line 103

Quoted 7 lines
src/pcm/pcm_direct.c +0 -1
@@ -98,7 +98,6 @@
 
 int snd_pcm_direct_shm_create_or_connect(snd_pcm_direct_t *dmix)
 {
-	static int snd_pcm_direct_shm_discard(snd_pcm_direct_t *dmix);
 	struct shmid_ds buf;
 	int ret = 0;
 

-------------------------------------------------------

Quoted 9 lines

This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn

#1 lore raw

At Fri, 23 Jan 2004 20:40:04 +1100,

Quoted 4 lines · Stephen Cook

I hope I don't sound to persistent but I am just wondering when this patch is going to be merged or if there is anything I can do to help speed it up. Such as any changes to the patch etc.

well, i'm also waiting for the response from others. for my eyes, it's no problem to apply...

Takashi

Quoted 118 lines

Thanks
Stephen
--

--------- Original Message ---------

DATE: Mon, 12 Jan 2004 15:03:54
From: Takashi Iwai <[email protected]>
To: [email protected]
Cc:

Quoted 89 lines

At Mon, 12 Jan 2004 12:27:23 +1100,

Quoted 9 lines · Stephen Cook

[1 <text/plain; us-ascii (7bit)>]
As you may be currently aware alsa-lib (libasound) does not work very well when using it under a kernel that has the Pax (http://pax.grsecurity.net) or Grsecurity (http://www.grsecurity.net) Patch.

The problem is because there is a function in a function (trampoline) - So gcc generates code that conflicts with pax. Also there is a text-relocation problem.

So I helped create patch that will fix these problems so alsa will be more usable on a Pax/Grsecurity machine (no chpax work arounds and more security). Currently this patch is included in alsa-lib-1.0.1 in Gentoo so it is undergoing large scale testing. For my part I have 2 machines running with Pax and this alsa-lib patch and I have had no problems :)

The code is a work around so if you know of a better way to do it please tell me.

i think this funciton-in-function is too dependent on gcc, too, and would like to get rid of it. the patch looks fine for me. or, we can add ifdef if someone still wants to keep the original style.

comments?

Takashi

Quoted 56 lines

____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005
[2 alsa-lib-1.0.1-notextrel-notrampoline.patch <text/plain; us-ascii (7bit)>]
diff -Nru alsa-lib-1.0.0rc2-original/src/control/hcontrol.c alsa-lib-1.0.0rc2/src/control/hcontrol.c

src/control/hcontrol.c +15 -5
@@ -48,6 +48,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <pthread.h>
 #ifndef DOC_HIDDEN
 #define __USE_GNU
 #endif
@@ -409,17 +410,26 @@
 	return 0;
 }
 
+static snd_hctl_t *compare_hctl;
+static int hctl_compare(const void *a, const void *b) {
+	return compare_hctl->compare(*(const snd_hctl_elem_t * const *) a,
+			     *(const snd_hctl_elem_t * const *) b);
+}
+
 static void snd_hctl_sort(snd_hctl_t *hctl)
 {
 	unsigned int k;
-	int compar(const void *a, const void *b) {
-		return hctl->compare(*(const snd_hctl_elem_t * const *) a,
-				     *(const snd_hctl_elem_t * const *) b);
-	}
+	static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER;
+
 	assert(hctl);
 	assert(hctl->compare);
 	INIT_LIST_HEAD(&hctl->elems);
-	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), compar);
+
+	pthread_mutex_lock(&sync_lock);
+	compare_hctl = hctl;
+	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), hctl_compare);
+	pthread_mutex_unlock(&sync_lock);
+
 	for (k = 0; k < hctl->count; k++)
 		list_add_tail(&hctl->pelems[k]->list, &hctl->elems);
 }

diff -Nru alsa-lib-1.0.0rc2-original/src/pcm/pcm_direct.c alsa-lib-1.0.0rc2/src/pcm/pcm_direct.c

src/pcm/pcm_direct.c line 103

Quoted 7 lines
src/pcm/pcm_direct.c +0 -1
@@ -98,7 +98,6 @@
 
 int snd_pcm_direct_shm_create_or_connect(snd_pcm_direct_t *dmix)
 {
-	static int snd_pcm_direct_shm_discard(snd_pcm_direct_t *dmix);
 	struct shmid_ds buf;
 	int ret = 0;
 

-------------------------------------------------------

Quoted 9 lines

This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005

Quoted 10 lines

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Alsa-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn

#2 lore raw
Quoted 13 lines · Takashi Iwai
Quoted 11 lines · Stephen Cook
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +5 -1
-	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), compar);
+
+	pthread_mutex_lock(&sync_lock);
+	compare_hctl = hctl;
+	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), hctl_compare);
+	pthread_mutex_unlock(&sync_lock);

I hope I don't sound to persistent but I am just wondering when this patch is going to be merged or if there is anything I can do to help speed it up. Such as any changes to the patch etc.

Quoted 1 line

well, i'm also waiting for the response from others.

Looks fine.

We're already dependent on pthreads, and qsort doesn't pass extra parameters, so I don't see any better way to do this. ("Let's write our own sorting routine" is not better IMNSHO.)

Regards,
Clemens

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn

#3 lore raw

At Mon, 26 Jan 2004 14:45:49 +0100 (MET),

Quoted 15 lines · Clemens Ladisch
Quoted 13 lines · Takashi Iwai
Quoted 11 lines · Stephen Cook
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +5 -1
-	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), compar);
+
+	pthread_mutex_lock(&sync_lock);
+	compare_hctl = hctl;
+	qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), hctl_compare);
+	pthread_mutex_unlock(&sync_lock);

I hope I don't sound to persistent but I am just wondering when this patch is going to be merged or if there is anything I can do to help speed it up. Such as any changes to the patch etc.

Quoted 7 lines
Quoted 1 line

well, i'm also waiting for the response from others.

Looks fine.

We're already dependent on pthreads, and qsort doesn't pass extra parameters, so I don't see any better way to do this. ("Let's write our own sorting routine" is not better IMNSHO.)

agreed. it's on cvs now.
(will be included in 1.0.2 release.)

thanks,

Takashi

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn