Skip to contentSkip to conversation

char: istallion: fix arbitrary kernel memory reads/writes

PATCH In review Vasiliy Kulikov 3 participants 4 messages Apr 9, 2011 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 char: istallion: fix arbitrary kernel memory reads/writes

stli_brdstats is defined as global variable. After de-BKL-ization in the patch b4eda9cb48eac1b7 an access to the variable is not serialized anymore. This leads to the TOCTOU in stli_getbrdstats():

        if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
                return -EFAULT;
        if (stli_brdstats.brd >= STL_MAXBRDS)  <<<<
                return -ENODEV;
        brdp = stli_brds[stli_brdstats.brd];   <<<<

If one process calls COM_GETBRDSTATS ioctl() with sane .brd, second process calls COM_GETBRDSTATS ioctl() with invalid .brd, and the second process' copy_from_user() executes exactly between the check and stli_brds[] indexation of the first process, then the first process gets contents of memory at *stli_brds[stli_brdstats.brd] address. Also the resulting .nrpanels field may be too big, in this case stli_brdstats.panels array overflows.

---
 drivers/char/istallion.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/istallion.c +1 -1
index 7c6de4c..232c5e0 100644
@@ -186,7 +186,6 @@ static struct ktermios		stli_deftermios = {
  *	re-used for each stats call.
  */
 static comstats_t	stli_comstats;
-static combrd_t		stli_brdstats;
 static struct asystats	stli_cdkstats;
 
 /*****************************************************************************/
@@ -4005,6 +4004,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
 {
 	struct stlibrd *brdp;
 	unsigned int i;
+	combrd_t stli_brdstats;
 
 	if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
 		return -EFAULT;
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 3 lines · Vasiliy Kulikov

stli_brdstats is defined as global variable. After de-BKL-ization in the patch b4eda9cb48eac1b7 an access to the variable is not serialized anymore. This leads to the TOCTOU in stli_getbrdstats():

Don't use such a weird and uncommon abbreviations.

drivers/char/istallion.c

Quoted 2 lines
drivers/char/istallion.c +0 -0

Note that the code moved to staging.

regards,

Signature · 1 line
js
#2 lore raw
Quoted 6 lines · Jiri Slaby
Quoted 3 lines · Vasiliy Kulikov

stli_brdstats is defined as global variable. After de-BKL-ization in the patch b4eda9cb48eac1b7 an access to the variable is not serialized anymore. This leads to the TOCTOU in stli_getbrdstats():

Don't use such a weird and uncommon abbreviations.

Time Of Check [to] Time Of Use. Hardly uncommon, especially in the security community. Googling for 'TOCTOU' and 'TOCTTOU' gets about 60K hits combined.

#3 lore raw
Quoted 10 lines · On 04/09/2011 10:24 PM, [email protected] wrote:
Quoted 6 lines · Jiri Slaby
Quoted 3 lines · Vasiliy Kulikov

stli_brdstats is defined as global variable. After de-BKL-ization in the patch b4eda9cb48eac1b7 an access to the variable is not serialized anymore. This leads to the TOCTOU in stli_getbrdstats():

Don't use such a weird and uncommon abbreviations.

Time Of Check [to] Time Of Use. Hardly uncommon, especially in the security community.

Well, changelogs are not for security community only. And I think I've read far than enough papers about code analysis and never seen that before.

Quoted 1 line

Googling for 'TOCTOU' and 'TOCTTOU' gets about 60K hits combined.

Sure, I googled that a bit. But that didn't persuade me at all. It looks like it is used by a narrow set of experts.

Whatever, I mainly wanted to point out the code move.

thanks,

Signature · 1 line
js