rt_task_inquire and NULL 2nd arg
Hello all,
I am testing some former programs with xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;
Calling rt_task_inquire(Id, NULL) with a null second argument now freezes or reboots the pc...
I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
Daniel
Signature · 5 lines
Daniel SIMON Projet NeCS INRIA Rhône-Alpes
Inovallée, 655 avenue de l'Europe, Montbonnot
38 334 Saint Ismier Cedex France
[email protected] Phone:(33)476615328 Fax:(33)476615252
http://necs.inrialpes.fr/people/simon/Quoted 9 lines · Daniel Simon
Hello all,
I am testing some former programs with xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;
Calling
rt_task_inquire(Id, NULL)with a null second argument now freezes or reboots the pc...I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
the rt_task_inquire system call checks that the "info" pointer points to a piece of writable memory and returns -EFAULT otherwise. So, what you should get is a segmentation fault, no freeze or reboot. Actually, I have tested a small test which segfaults as expected. Could you provide us with the simple test that causes a freeze or reboot ?
Signature · 1 line
Gilles Chanteperdrix.
Quoted 6 lines · On Wed, 31 Oct 2007 21:09:34 +0100 Gilles Chanteperdrix…
Quoted 5 lines · Daniel Simon
Hello all,
I am testing some former programs with
xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;
Quoted 8 lines
Quoted 5 lines
Calling
rt_task_inquire(Id, NULL)with a null second argument now freezes or reboots the pc...I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
the
rt_task_inquiresystem call checks that the "info" pointer points to a piece of writable memory and returns-EFAULTotherwise.
That was the behaviour I got with xenomai-2.3.1 (I only wanted to check if the task was still existing and thus only interested in the value returned)
Quoted 5 lines
So, what you
should get is a segmentation fault, no freeze or reboot. Actually, I have tested a small test which segfaults as expected. Could you provide us with the simple test that causes a freeze or reboot ?
file testinfo.c and config attached, uncommenting line 201 reboots the system at cleaning time after ^C
(xeno 2.4-rc5, kernel 2.6.23.1, gcc 4.0.2 with --xeno-cflags and --xeno-ldflags)
Daniel
Signature · 5 lines
Daniel SIMON Projet NeCS INRIA Rhône-Alpes
Inovallée, 655 avenue de l'Europe, Montbonnot
38 334 Saint Ismier Cedex France
[email protected] Phone:(33)476615328 Fax:(33)476615252
http://necs.inrialpes.fr/people/simon/#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <math.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <native/types.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/timer.h>
#include <native/sem.h>
#include <native/alarm.h>
#include <native/heap.h>
#include <native/queue.h>
#include <native/syscall.h>
#define STACK_SIZE 8192
#define MIN_PRIO 1
#define MAX_PRIO 99
#define PRI_MT_MAX MAX_PRIO - 6
#define PRI_MT_MIN MIN_PRIO
typedef void * (*FUNCPTR) (void *);
typedef void (*SOSO) (void *); /**< Special type to be used for casting in task_create() */ #define ORCMSGQ RT_QUEUE * /**< Message Queue Type */
#define ORCSEM_ID RT_SEM * /**< Semaphore Type */
#define ORCFULL 1 /**< State of a Full Binary Semaphore */
#define ORCEMPTY 0 /**< State of a Empty Binary Semaphore */
#define ORCFOREVER TM_INFINITE /**< State of a ??? Binary Semaphore */
#define SIZE_QUEUE 100 /**< Size of the Message Queue */
#define SIZE_MES_MAX 4056 /**< Maximum size of a message in Message Queue */
#define SIZE_MES_MIN 128 /**< Minimum size of a message in Message Queue */
/*-------Tasks----------*/
#define ORCTHR_ID RT_TASK * /**< Xeno RT-Task Type */
#define STACKSIZE int /**< Stack size Type */
#define SCHED_OTHER 0 #define SCHED_FIFO 1 #define SCHED_RR 2 #define SCHEDPOLICY SCHED_FIFO /**< Scheduling policy (see schedbits.h, sched.h )*/
#define SMALL_STACK 1000 /**< Small task stack size PTHREAD_STACK_MIN not defined */
#define NORMAL_STACK (5*SMALL_STACK) /**< Normal task stack size */
#define BIG_STACK (15*SMALL_STACK) /**< Big task stack size */
// --s-ms-us-ns
RTIME task_period_ns = 500000000llu;
#define NSEC_PER_SEC 1000000000
#define OK 0
#define ERROR -1
#define STATUS int
#define FALSE 0
#define TRUE 1
#define POLICY 1
static int ji = 0;
//static int togparport = 0;
static RTIME startime, now; // inittime, nexttime; struct timespec clock_resolution;
static int message_counter = 0;
RT_ALARM BaseClk;
int status, err, end = 0, loops = 10;
char *dummy;
ORCTHR_ID thr_clockit;ORCTHR_ID thr_loop;
ORCMSGQ Queue;
ORCSEM_ID SynchroSem;
static int cpt_sem = 10000;
char nameSem[10];
int crexec, cr;RT_TASK_INFO info;
long past = 0;ORCTHR_ID MAIN_RT;
/*-------Semaphores----------*/
/**
* Function to create a semaphore
*
* @param initState semaphore initial creation state, eg ORCFULL, ORCEMPTY
* @return ORCSEM_ID semaphore pointer created if successfull, NULL otherwise
* @see ORCFULL
* @see ORCEMPTY
* @see <semaphore.h>#sem_init
*/
ORCSEM_ID orcSemCreate(int initState)
{
ORCSEM_ID newSem;
int status;
sprintf(nameSem,"%d",cpt_sem);
newSem = malloc(sizeof(RT_SEM));
if (newSem == 0)
{
printf("ERROR orcSem init \n");
return 0;
}
memset(newSem, 0, sizeof(RT_SEM));
if(initState == ORCFULL)
{
status = rt_sem_create(newSem, nameSem, initState, S_FIFO);
#ifdef DEBUG
printf("WARNING binary Sem created FULL \n");
#endif
}
else
status = rt_sem_create(newSem, nameSem, initState, S_FIFO|S_PULSE);
if (status == OK)
{
#ifdef DEBUG
printf("orcSemCreate %p\n", newSem);
#endif
cpt_sem++;
return newSem;
}
else
{
#ifdef DEBUG
printf("orcSemCreate ERROR %d\n", status);
#endif
return NULL;
}
}/**
* Function to delete a given semaphore
*
* @param sem semaphore to be deleted
* @return sem_destroy() returned value
* @see <semaphore.h>#sem_destroy
*/
int orcSemDelete(ORCSEM_ID sem)
{
if (sem == 0)
return ERROR;
if (rt_sem_delete(sem) == 0)
{
free(sem);
return OK;
}
printf("Erreur:orcSemDelete\n");
return ERROR;
}/**
* Function to give a semaphore
*
* @param sem semaphore id
* @return sem_post) returned value
* @see <semaphore.h>#sem_post
*/
int orcSemGive(ORCSEM_ID sem)
{
#ifdef DEBUG
printf("SemGive %p\n", sem);
#endif
return (rt_sem_v(sem));
}/**
* Function to take a semaphore
* TODO : no timeout in Posix semaphores
*
* @param sem semaphore
* @param timeout value
* @return sem_wait() returned value
* @see <semaphore.h>#sem_wait
*/
int orcSemTake(ORCSEM_ID sem, int timeout)
{
#ifdef DEBUG
printf("SemTake %p\n", sem);
#endif
return (rt_sem_p(sem, timeout));
}/*-------Tasks----------*/
/**
* Function to check if a task is still valid or not *
* @param Id task identifier
* @return OK if task is valid, ERROR otherwise
* @see ORCTHR_ID
* @see pthread_kill
*/
int orcTaskIdVerify(ORCTHR_ID Id)
{
int cr;
RT_TASK_INFO info;
cr = rt_task_inquire(Id,&info);
/* cr = rt_task_inquire(Id,NULL); */
if (cr == 0)
{
printf("orcTaskIdVerify %p OK \n", Id);
return OK;
}
printf("orcTaskIdVerify %p ERROR %d\n", Id, cr);
return ERROR;
}/**
* Function to kill a task (pthread)
*
* @param Id task identifier
* @return ERROR or pthread_cancel returned value
* @see ORCTHR_ID
* @see <pthread.h>#pthread_kill
* @see <pthread.h>#pthread_cancel
*/
int orcTaskDelete(ORCTHR_ID task)
{
int result;
if (task == 0)
{
printf("ERROR rt_task_delete, task == 0\n");
return ERROR;
}
result = rt_task_delete(task);
if (result != 0)
{
printf("ERROR rt_task_delete %p error %d\n", task, result);
return ERROR;
}
// if (result == 0)
free(task);
return OK;
}/**
* Function to spawn a task
*
* @param tid task identifier
* @param name name descripting the task
* @param prio task priority level
* @param stackSize stack size to be allocated for the task
* @param funcptr routine to be spawn by the task
* @param arg argument needed for the routine to be spawn
* @return pthread_create returned value
* @see ORCTHR_ID
* @see STACKSIZE
* @see FUNCPTR
* @see <pthread.h>#pthread_create
*/
int orcSpawn(ORCTHR_ID *tid, const char *name, int prio, STACKSIZE stackSize, SOSO funcptr, void * arg)
{
int err;
//Allocate memory
if (((*tid) = (RT_TASK*) malloc (sizeof(RT_TASK))) == NULL)
{
printf("Error malloc orcspawn\n" );
return ERROR;
}
if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU|T_JOINABLE|T_CPU(0), (SOSO) funcptr, arg)) != 0)
//if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU, (SOSO) funcptr, arg)) != 0)
{
printf("ERROR %d rt_task_init\n", err);
return ERROR;
}
//#ifdef DEBUG
printf("rt_task create %s prio %d StackSize %d Id %p \n", name, prio, stackSize, *tid);
//#endif
return OK;
}
int orcSpawn1(ORCTHR_ID *tid, const char *name, int prio, STACKSIZE stackSize, SOSO funcptr, void * arg)
{
int err;
//Allocate memory
if (((*tid) = (RT_TASK*) malloc (sizeof(RT_TASK))) == NULL)
{
printf("Error malloc orcspawn\n" );
return ERROR;
}
if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU|T_JOINABLE|T_CPU(1), (SOSO) funcptr, arg)) != 0)
//if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU, (SOSO) funcptr, arg)) != 0)
{
printf("ERROR %d rt_task_init\n", err);
return ERROR;
}
//#ifdef DEBUG
printf("rt_task create %s prio %d StackSize %d Id %p \n", name, prio, stackSize, *tid);
//#endif
return OK;
}///Function that returns the cpu time in nanoseconds inline long long GetCpuTime(void)
{
return (long long)rt_timer_ticks2ns(rt_timer_read());
}inline long long orcGetExecTime(ORCTHR_ID task)
{
crexec = rt_task_inquire(task,&info);
if (crexec != 0){
printf("rt_task_get_exectime error %d \n", crexec);
return (long long)0;} else return (long long)info.exectime;
}
inline long long orcGetStartTime(ORCTHR_ID task)
{
return (long long)0;
}int orcMakeRealTime(void)
{
int prio_main = PRI_MT_MAX + 1;
mlockall(MCL_CURRENT | MCL_FUTURE);
if ((cr = rt_task_shadow(MAIN_RT, "MAIN_PRR", prio_main, T_FPU | T_JOINABLE)) != 0)
{printf("rt_task_shadow error %d \n", cr);}
else {printf("rt_task_shadow done priority %d \n", prio_main);}
return cr;
}int orcTaskJoin(ORCTHR_ID task)
{
cr = rt_task_join(task);
if (cr != 0){
printf("rt_task_join error %d on task %p \n", cr, task); return cr;}
else return OK;
}
// Trap Ctrl C Interruption
void clean_exit(int dummy)
{
printf("Ctrl C Interrupt\n");
end = 1;
orcTaskIdVerify(thr_clockit);
orcTaskIdVerify(thr_loop);
err = rt_task_join(thr_clockit);
if (err != 0)printf("rt_task_join() error %d \n", err);
err = rt_task_join(thr_loop);
if (err != 0)printf("rt_task_join() error %d \n", err);
printf("deleting rt devices \n");
err = rt_alarm_delete(&BaseClk);
if (err != 0)printf("rt_alarm_delete() error %d \n", err);
orcSemDelete(SynchroSem);
return ;
}int orcTimerSigMask(void)
{
sigset_t set;
sigfillset(&set);
if ((err = pthread_sigmask(SIG_BLOCK, &set, NULL)) != OK)
{
printf("pthread_sigmask Failed %d \n", err);
return ERROR;
}
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
if ((err = pthread_sigmask(SIG_UNBLOCK, &set, NULL)) != OK)
{
printf("pthread_sigmask Failed %d \n", err);
return ERROR;
}
return OK;
}void setTimer(void)
{
/***starting timer ***/
err = rt_alarm_create(&BaseClk, "BaseClock");
if (err != 0)printf("rt_alarm_create() error %d \n", err);
err = rt_alarm_start(&BaseClk,
rt_timer_ns2ticks(task_period_ns),
rt_timer_ns2ticks(task_period_ns));
if (err != 0)printf("rt_alarm_start() error %d \n", err);
else printf("alarm started with period %llu ns \n", task_period_ns);
printf("period in ticks %ld \n", (long)rt_timer_ns2ticks(task_period_ns));
return ;}
long long loopbusytime, clockbusytime;
void clock_it(void)
{
int msg = 1;
long long clockexectime, clockdiff;
static long long clockpast = 0;
while (!end)
{
err = rt_alarm_wait(&BaseClk);
clockbusytime = 30000000;
rt_timer_spin((RTIME)clockbusytime);
msg++;
printf("clock_it \n");
orcSemGive(SynchroSem);
}
return ;
}
void func_loop()
{
while (!end)
{
orcSemTake(SynchroSem, ORCFOREVER);
loopbusytime = 20000000;
rt_timer_spin((RTIME)loopbusytime);
printf("func_loop \n");
}
return;
}int main(void)
{
orcTimerSigMask();
signal(SIGTERM, clean_exit);
signal(SIGINT, clean_exit);
orcMakeRealTime();
setTimer();
SynchroSem = orcSemCreate(ORCEMPTY);
orcSpawn(&thr_clockit, "AlarmServer", MAX_PRIO, NORMAL_STACK, (SOSO) clock_it, NULL);
orcSpawn(&thr_loop, "Loop", MAX_PRIO - 1, NORMAL_STACK, (SOSO) func_loop, NULL);
pause();
fflush(NULL);
return 0;
}Quoted 20 lines · Daniel Simon
Quoted 6 lines · On Wed, 31 Oct 2007 21:09:34 +0100 Gilles Chanteperdrix…
Quoted 5 lines · Daniel Simon
Hello all,
I am testing some former programs with
xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;Quoted 8 lines
Quoted 5 lines
Calling
rt_task_inquire(Id, NULL)with a null second argument now freezes or reboots the pc...I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
the
rt_task_inquiresystem call checks that the "info" pointer points to a piece of writable memory and returns-EFAULTotherwise.That was the behaviour I got with xenomai-2.3.1 (I only wanted to check if the task was still existing and thus only interested in the value returned)
Quoted 9 lines
Quoted 5 lines
So, what you
should get is a segmentation fault, no freeze or reboot. Actually, I have tested a small test which segfaults as expected. Could you provide us with the simple test that causes a freeze or reboot ?file
testinfo.cand config attached, uncommenting line 201 reboots the system at cleaning time after ^C
(xeno 2.4-rc5, kernel 2.6.23.1, gcc 4.0.2 with --xeno-cflags and --xeno-ldflags)
As a matter of fact, the address checking code on x86* considers any address below the page offset as being valid, so passing NULL went undetected in your case. This was already the case with 2.3.1, you likely just got lucky with respect to the consequences of another hole - in the I-pipe this time - which has been plugged recently, and now fixes up any fault whenever Xenomai has to leave it unhandled:
http://www.denx.de/cgi-bin/gitweb.cgi?p=ipipe-2.6.git;a=commit;h=e7b140c69794521fe8979a39337f36112dbe330c
The fix above was only available when CONFIG_IPIPE_DEBUG was enabled in the latest patch series, and prevented any ungraceful consequence of writing to an invalid address from the Xenomai domain. We actually need to have this fixup done in any case. Next I-pipe patches will include this change.
In short, rt_task_inquire() has never been meant to accept a NULL parameter so far, and doing so was not properly caught at Xenomai level. When using the invalid pointer that went undetected for writing the output data back, some I-pipe issue let the resulting access fault unhandled, causing a general panic state in the kernel whenever the fixup above was not active (older I-pipe support or CONFIG_IPIPE_DEBUG disabled).
I've slightly improved the address checking code for x86 32/64, so that it also detects any address lower than the natural page size, which would have caught the NULL case. We can't do much more, at least on the fast path, than detecting addresses lower than PAGE_SIZE or located in kernel memory. Other spurious addresses should trigger a segmentation violation, which should be properly handled in all cases using an I-pipe /x86 patch beyond 1.10-11 (the same goes for x86_64, beyond 1.2-05).
Now, it seems reasonable to ask rt_task_inquire() to test whether the target task exists or not, in which case it may be acceptable to pass a NULL buffer. This change will likely be applied to the trunk asap, and will be part of -rc6.
Signature · 1 line
Philippe.
Quoted 26 lines · Philippe Gerum
Quoted 25 lines · Daniel Simon
Quoted 6 lines · On Wed, 31 Oct 2007 21:09:34 +0100 Gilles Chanteperdrix…
Quoted 5 lines · Daniel Simon
Hello all,
I am testing some former programs with
xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;Quoted 8 lines
Quoted 5 lines
Calling
rt_task_inquire(Id, NULL)with a null second argument now freezes or reboots the pc...I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
the
rt_task_inquiresystem call checks that the "info" pointer points to a piece of writable memory and returns-EFAULTotherwise.That was the behaviour I got with xenomai-2.3.1 (I only wanted to check if the task was still existing and thus only interested in the value returned)
Quoted 5 lines
So, what you
should get is a segmentation fault, no freeze or reboot. Actually, I have tested a small test which segfaults as expected. Could you provide us with the simple test that causes a freeze or reboot ?
Quoted 7 lines
Quoted 4 lines
file
testinfo.cand config attached, uncommenting line 201 reboots the system at cleaning time after ^C
(xeno 2.4-rc5, kernel 2.6.23.1, gcc 4.0.2 with --xeno-cflags and --xeno-ldflags)As a matter of fact, the address checking code on x86* considers any address below the page offset as being valid, so passing NULL went
Could you explain why Xenomai is special here? The range-checking macros matched mainline before (as it should be), now it is different without any (at least to) obvious reason. Their purpose is not to avoid page faults but to avoid "confused deputy" attacks (user making the kernel accessing privileged memory).
Quoted 5 lines
undetected in your case. This was already the case with 2.3.1, you likely just got lucky with respect to the consequences of another hole - in the I-pipe this time - which has been plugged recently, and now fixes up any fault whenever Xenomai has to leave it unhandled:
http://www.denx.de/cgi-bin/gitweb.cgi?p=ipipe-2.6.git;a=commit;h=e7b140c69794521fe8979a39337f36112dbe330c
Err, my feeling is you misunderstand this.
Quoted 4 lines
The fix above was only available when
CONFIG_IPIPE_DEBUGwas enabled in the latest patch series, and prevented any ungraceful consequence of writing to an invalid address from the Xenomai domain. We actually need
Nope, it is intended to catch *improperly handled* invalid memory accesses, ie. non-root domain bugs in the kernel.
Quoted 2 lines
to have this fixup done in any case. Next I-pipe patches will include this change.
I'm not sure if we need this debugging feature on by default - in the fast path of Linux code running on usual page faults. The check must never fire unless the RT domain's kernel is buggy, thus we should only use it during debugging.
Something is fishy here - or I'm still missing the point. The question for me is: Why was the NULL pointer access over Xenomai passed through without relaxing the caller, which then causes all those lethal corruptions? Were you able to reproduce this case and understand what goes wrong, Philippe?
Quoted 9 lines
In short,
rt_task_inquire()has never been meant to accept a NULL parameter so far, and doing so was not properly caught at Xenomai level. When using the invalid pointer that went undetected for writing the output data back, some I-pipe issue let the resulting access fault unhandled, causing a general panic state in the kernel whenever the fixup above was not active (older I-pipe support orCONFIG_IPIPE_DEBUGdisabled).
Quoted 7 lines
I've slightly improved the address checking code for x86 32/64, so that it also detects any address lower than the natural page size, which would have caught the NULL case. We can't do much more, at least on the fast path, than detecting addresses lower than
PAGE_SIZEor located in kernel memory. Other spurious addresses should trigger a segmentation violation, which should be properly handled in all cases using an I-pipe /x86 patch beyond 1.10-11 (the same goes forx86_64, beyond 1.2-05).
Sorry, makes no sense to me. If the user makes us accessing the NULL page, we receive a nice trap, relax the thread, and ideally report the bug as EFAULT back to the user, no?
Quoted 6 lines
Now, it seems reasonable to ask
rt_task_inquire()to test whether the target task exists or not, in which case it may be acceptable to pass a NULL buffer. This change will likely be applied to the trunk asap, and will be part of -rc6.
Jan
Quoted 31 lines · Jan Kiszka
Quoted 30 lines · Philippe Gerum
Quoted 29 lines · Daniel Simon
Quoted 6 lines · On Wed, 31 Oct 2007 21:09:34 +0100 Gilles Chanteperdrix…
Quoted 5 lines · Daniel Simon
Hello all,
I am testing some former programs with
xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;Quoted 8 lines
Quoted 5 lines
Calling
rt_task_inquire(Id, NULL)with a null second argument now freezes or reboots the pc...I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
the
rt_task_inquiresystem call checks that the "info" pointer points to a piece of writable memory and returns-EFAULTotherwise.That was the behaviour I got with xenomai-2.3.1 (I only wanted to check if the task was still existing and thus only interested in the value returned)
Quoted 5 lines
So, what you
should get is a segmentation fault, no freeze or reboot. Actually, I have tested a small test which segfaults as expected. Could you provide us with the simple test that causes a freeze or reboot ?file
testinfo.cand config attached, uncommenting line 201 reboots the system at cleaning time after ^C
(xeno 2.4-rc5, kernel 2.6.23.1, gcc 4.0.2 with --xeno-cflags and --xeno-ldflags)
Quoted 9 lines
Quoted 2 lines
As a matter of fact, the address checking code on x86* considers any address below the page offset as being valid, so passing NULL went
Could you explain why Xenomai is special here? The range-checking macros matched mainline before (as it should be), now it is different without any (at least to) obvious reason. Their purpose is not to avoid page faults but to avoid "confused deputy" attacks (user making the kernel accessing privileged memory).
Mainline macros only check for (addr < PAGE_OFFSET), which basically says that any address below the first kernel location is ok. The rest is expected to be caught by the usual exception mechanism. Because of the dual domain model, we have to fixup things that Linux hasn't.
Quoted 6 lines
Quoted 5 lines
undetected in your case. This was already the case with 2.3.1, you likely just got lucky with respect to the consequences of another hole - in the I-pipe this time - which has been plugged recently, and now fixes up any fault whenever Xenomai has to leave it unhandled:
http://www.denx.de/cgi-bin/gitweb.cgi?p=ipipe-2.6.git;a=commit;h=e7b140c69794521fe8979a39337f36112dbe330c
Quoted 9 lines
Err, my feeling is you misunderstand this.
Quoted 3 lines
The fix above was only available when
CONFIG_IPIPE_DEBUGwas enabled in the latest patch series, and prevented any ungraceful consequence of writing to an invalid address from the Xenomai domain. We actually needNope, it is intended to catch *improperly handled* invalid memory accesses, ie. non-root domain bugs in the kernel.
You are missing the major issue: there is some situations where Xenomai will never handle a fault occurring on top of the Xenomai domain, because it has not really be triggered by a shadow, but rather by a pure Linux thread running a syscall in high stage. This is the case for those running __xn_exec_any flagged services, like rt_task_inquire. And no, we don't want to turn __xn_exec_any services into __xn_exec_conforming ones, because there is no point in having real-time threads calling such services from secondary mode to be uselessly switched to primary mode.
Quoted 7 lines
Quoted 2 lines
to have this fixup done in any case. Next I-pipe patches will include this change.
I'm not sure if we need this debugging feature on by default - in the fast path of Linux code running on usual page faults. The check must never fire unless the RT domain's kernel is buggy, thus we should only use it during debugging.
As explained, some situations should better be left to the I-pipe as a fallback situation. This is what is going to happen with the next patches.
What we have to do is the fixup always, only enabling the debug message and the trace freeze according to the IPIPE_DEBUG knob. The rationale is
simple: those situations are bugous, but should not be lethal, because Linux normally allows for the fault to occur, so we should allow this too. But since this reveals a problem, this has to be reported in the message log when running in debug mode, since we cannot propagate this information in any other way.
Quoted 4 lines
Something is fishy here - or I'm still missing the point. The question for me is: Why was the NULL pointer access over Xenomai passed through without relaxing the caller,
The caller was _NOT_ running as a shadow. You may have tasks running as pure Linux threads in the Xenomai domain. In such a case, Xenomai _cannot_ handle the situation by itself, and needs the help of the I-pipe, because only the I-pipe is allowed to switch domains.
Signature · 1 line
Philippe.
Quoted 41 lines · Philippe Gerum
Quoted 31 lines · Jan Kiszka
Quoted 30 lines · Philippe Gerum
Quoted 29 lines · Daniel Simon
Quoted 6 lines · On Wed, 31 Oct 2007 21:09:34 +0100 Gilles Chanteperdrix…
Quoted 5 lines · Daniel Simon
Hello all,
I am testing some former programs with
xenomai-2.4-rc4/kernel-2.6.23.1/pentiumM;Quoted 8 lines
Quoted 5 lines
Calling
rt_task_inquire(Id, NULL)with a null second argument now freezes or reboots the pc...I had no problem with this call with a former (2.3.1) xenomai version. Is it a known behaviour?
the
rt_task_inquiresystem call checks that the "info" pointer points to a piece of writable memory and returns-EFAULTotherwise.That was the behaviour I got with xenomai-2.3.1 (I only wanted to check if the task was still existing and thus only interested in the value returned)
Quoted 5 lines
So, what you
should get is a segmentation fault, no freeze or reboot. Actually, I have tested a small test which segfaults as expected. Could you provide us with the simple test that causes a freeze or reboot ?file
testinfo.cand config attached, uncommenting line 201 reboots the system at cleaning time after ^C
(xeno 2.4-rc5, kernel 2.6.23.1, gcc 4.0.2 with --xeno-cflags and --xeno-ldflags)Quoted 8 lines
Quoted 2 lines
As a matter of fact, the address checking code on x86* considers any address below the page offset as being valid, so passing NULL went
Could you explain why Xenomai is special here? The range-checking macros matched mainline before (as it should be), now it is different without any (at least to) obvious reason. Their purpose is not to avoid page faults but to avoid "confused deputy" attacks (user making the kernel accessing privileged memory).
Quoted 4 lines
Mainline macros only check for (addr <
PAGE_OFFSET), which basically says that any address below the first kernel location is ok. The rest is expected to be caught by the usual exception mechanism. Because of the dual domain model, we have to fixup things that Linux hasn't.
What things precisely? Maybe just a clarifying comment is lacking in the code, though for me this patch still looks unrelated to the issue below.
Quoted 34 lines
Quoted 6 lines
Quoted 6 lines
undetected in your case. This was already the case with 2.3.1, you likely just got lucky with respect to the consequences of another hole - in the I-pipe this time - which has been plugged recently, and now fixes up any fault whenever Xenomai has to leave it unhandled:
http://www.denx.de/cgi-bin/gitweb.cgi?p=ipipe-2.6.git;a=commit;h=e7b140c69794521fe8979a39337f36112dbe330cQuoted 8 lines
Err, my feeling is you misunderstand this.
Quoted 3 lines
The fix above was only available when
CONFIG_IPIPE_DEBUGwas enabled in the latest patch series, and prevented any ungraceful consequence of writing to an invalid address from the Xenomai domain. We actually needNope, it is intended to catch *improperly handled* invalid memory accesses, ie. non-root domain bugs in the kernel.
You are missing the major issue: there is some situations where Xenomai will never handle a fault occurring on top of the Xenomai domain, because it has not really be triggered by a shadow, but rather by a pure Linux thread running a syscall in high stage. This is the case for those running
__xn_exec_anyflagged services, likert_task_inquire. And no, we don't want to turn__xn_exec_anyservices into__xn_exec_conformingones, because there is no point in having real-time threads calling such services from secondary mode to be uselessly switched to primary mode.Quoted 6 lines
Quoted 2 lines
to have this fixup done in any case. Next I-pipe patches will include this change.
I'm not sure if we need this debugging feature on by default - in the fast path of Linux code running on usual page faults. The check must never fire unless the RT domain's kernel is buggy, thus we should only use it during debugging.
As explained, some situations should better be left to the I-pipe as a fallback situation. This is what is going to happen with the next patches.
Quoted 7 lines
What we have to do is the fixup always, only enabling the debug message and the trace freeze according to the
IPIPE_DEBUGknob. The rationale is
simple: those situations are bugous, but should not be lethal, because Linux normally allows for the fault to occur, so we should allow this too. But since this reveals a problem, this has to be reported in the message log when running in debug mode, since we cannot propagate this information in any other way.
OK, got it. We do have a case now where faults happen over non-root domains and are not a kernel faults. But such faults, even though they are not OK, shall not uselessly flood our kernel console. Instead, we need to switch silently and let Linux handle them. If the faults are fixable (like in this case), we are fine again. If not, we see the usual oops. Maybe we can track - silently - if there was a switch back earlier in order to report the original domain in the oops.
Quoted 10 lines
Quoted 4 lines
Something is fishy here - or I'm still missing the point. The question for me is: Why was the NULL pointer access over Xenomai passed through without relaxing the caller,
The caller was _NOT_ running as a shadow. You may have tasks running as pure Linux threads in the Xenomai domain. In such a case, Xenomai _cannot_ handle the situation by itself, and needs the help of the I-pipe, because only the I-pipe is allowed to switch domains.
Ack. Still, this fiddling with __xn_access_ok is totally unclear to me.
Jan