PPC64 rtasd: window when error_log_cnt could get zeroed
PATCH 1/1 PPC64 rtasd: window when error_log_cnt could get zeroed
This patch is from Jake Moilanen <[email protected]>.
There appears to be a hole that if we get an log_error() call, that we could zero out our error log count in nvram.
When rtasd() starts up, it turns on the logging via 'no_more_logging = 0'. If we get a log_error() call after that is set but before nvram_read_error_log has actually read nvram to set error_log_cnt, the log_error() call will write back to nvram a uninitialized error_log_cnt value, and wipe out our sequence number.
To close the hole, simply move the 'no_more_logging = 0' till after nvram sets error_log_cnt but before pSeries_log_error is called.
I also changed the 'no_more_logging' variable to be 'no_logging' since it's not only used when we stop logging now. I also removed the "volatile" part of no_more_logging, since it's unneeded.
arch/ppc64/kernel/rtasd.c renamed from arch/ppc64/kernel/rtasd.c~rtasd-no_more_logging-race +9 -8
@@ -48,7 +48,7 @@ static unsigned int rtas_error_log_buffestatic int full_rtas_msgs =0 ; -extern volatile int no_more_logging; +extern int no_logging;volatile int error_log_cnt =0 ;
@@ -213,7 +213,7 @@ void pSeries_log_error(char *buf, unsign }/* Write error to NVRAM */ -if (!no_more_logging && !(err_type &ERR_FLAG_BOOT )) +if (!no_logging && !(err_type &ERR_FLAG_BOOT ))nvram_write_error_log (buf, len, err_type);/*
@@ -225,8 +225,8 @@ void pSeries_log_error(char *buf, unsignprintk_log_rtas (buf, len);/* Check to see if we need to or have stopped logging */ -if (fatal || no_more_logging) { - no_more_logging =1 ; +if (fatal || no_logging) { + no_logging =1 ;spin_unlock_irqrestore (&rtasd_log_lock, s);return ; }
@@ -299,7 +299,7 @@ static ssize_t rtas_log_read(struct filespin_lock_irqsave (&rtasd_log_lock, s);/* if it's 0, then we know we got the last one (the one in NVRAM) */ -if (rtas_log_size ==0 && !no_more_logging) +if (rtas_log_size ==0 && !no_logging)nvram_clear_error_log ();spin_unlock_irqrestore (&rtasd_log_lock, s);
@@ -417,9 +417,6 @@ static int rtasd(void *unused) goto error; } -/* We can use rtas_log_buf now */ - no_more_logging =0 ; -printk (KERN_ERR "RTAS daemon started\n" );DEBUG ("will sleep for %d jiffies\n" , (HZ *60 /rtas_event_scan_rate) /2 );
@@ -428,6 +425,10 @@ static int rtasd(void *unused)memset (logdata,0 , rtas_error_log_max); rc =nvram_read_error_log (logdata, rtas_error_log_max, &err_type); + +/* We can use rtas_log_buf now */ + no_logging =0 ; +if (!rc) {if (err_type !=ERR_FLAG_ALREADY_LOGGED ) {pSeries_log_error (logdata, err_type |ERR_FLAG_BOOT ,0 );
arch/ppc64/kernel/nvram.c renamed from arch/ppc64/kernel/nvram.c~rtasd-no_more_logging-race +4 -4
@@ -43,9 +43,9 @@ static struct nvram_partition * nvram_pastatic long nvram_error_log_index =-1 ;static long nvram_error_log_size =0 ; -volatile int no_more_logging =1 ;/* Until we initialize everything, -* make sure we don't try logging -* anything */ +int no_logging =1 ;/* Until we initialize everything, +* make sure we don't try logging +* anything */ extern volatile int error_log_cnt;
@@ -640,7 +640,7 @@ int nvram_write_error_log(char * buff, iloff_t tmp_index;struct err_log_info info; -if (no_more_logging) { +if (no_logging) {return -EPERM ; }