mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vincent Pelletier <subdino2004@yahoo.fr>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Re: 2.6.10 : fs/openpromfs/inode.c : small mistakes makes module oops   when writing
Date: Wed, 05 Jan 2005 16:39:21 +0100	[thread overview]
Message-ID: <crh1ni$v8$1@sea.gmane.org> (raw)
In-Reply-To: <crbg4j$vbr$1@sea.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 334 bytes --]

Hello.

Here is the patch.

Changelog:
	2005/01/05  Vincent Pelletier  <subdino2004@yahoo.fr>
	inode.c: (nodenum_read, property_read, property_write):
	Protected against NULL parameters. property_read: Returns 0 when
	called with a 0-length buffer. (property_write): Don't expect an
	hex list to begin with a dot.

Vincent Pelletier


[-- Attachment #1.2: openpromfs.diff --]
[-- Type: text/plain, Size: 2888 bytes --]

--- linux-2.6.10/fs/openpromfs/inode.c	2004-12-24 22:34:44.000000000 +0100
+++ linux-2.6.10-openpromfs/fs/openpromfs/inode.c	2005-01-05 16:35:46.345978153 +0100
@@ -67,14 +67,15 @@
 static ssize_t nodenum_read(struct file *file, char __user *buf,
 			    size_t count, loff_t *ppos)
 {
-	struct inode *inode = file->f_dentry->d_inode;
+	struct inode *inode;
 	char buffer[10];
 	
-	if (count < 0 || !inode->u.generic_ip)
+	if (!file || !buf || !ppos || !file->f_dentry || !file->f_dentry->d_inode)
 		return -EINVAL;
-	sprintf (buffer, "%8.8x\n", (u32)(long)(inode->u.generic_ip));
 	if (file->f_pos >= 9)
 		return 0;
+	inode = file->f_dentry->d_inode;
+	sprintf (buffer, "%8.8x\n", (u32)(long)(inode->u.generic_ip));
 	if (count > 9 - file->f_pos)
 		count = 9 - file->f_pos;
 	if (copy_to_user(buf, buffer + file->f_pos, count))
@@ -86,7 +87,7 @@
 static ssize_t property_read(struct file *filp, char __user *buf,
 			     size_t count, loff_t *ppos)
 {
-	struct inode *inode = filp->f_dentry->d_inode;
+	struct inode *inode;
 	int i, j, k;
 	u32 node;
 	char *p, *s;
@@ -94,9 +95,12 @@
 	openprom_property *op;
 	char buffer[64];
 	
-	if (*ppos >= 0xffffff || count >= 0xffffff)
+	if (!filp || count >= 0xffffff || (count && !buf) || (ppos && *ppos >= 0xffffff) || !filp->f_dentry || !filp->f_dentry->d_inode)
 		return -EINVAL;
+	inode = filp->f_dentry->d_inode;
 	if (!filp->private_data) {
+		if(!nodes)
+			return -EIO;
 		node = nodes[(u16)((long)inode->u.generic_ip)].node;
 		i = ((u32)(long)inode->u.generic_ip) >> 16;
 		if ((u16)((long)inode->u.generic_ip) == aliases) {
@@ -166,7 +170,7 @@
 		}
 	} else
 		op = (openprom_property *)filp->private_data;
-	if (!count || !(op->len || (op->flag & OPP_ASCIIZ)))
+	if (!ppos || !count || !(op->len || (op->flag & OPP_ASCIIZ)))
 		return 0;
 	if (op->flag & OPP_STRINGLIST) {
 		for (k = 0, p = op->value; p < op->value + op->len; p++)
@@ -327,7 +331,7 @@
 	void *b;
 	openprom_property *op;
 	
-	if (*ppos >= 0xffffff || count >= 0xffffff)
+	if (!filp || !ppos || *ppos >= 0xffffff || count >= 0xffffff || (count && !buf))
 		return -EINVAL;
 	if (!filp->private_data) {
 		i = property_read (filp, NULL, 0, NULL);
@@ -343,13 +347,11 @@
 		char tmp [9];
 		int forcelen = 0;
 		
-		j = k % 9;
-		for (i = 0; i < count; i++, j++) {
-			if (j == 9) j = 0;
-			if (!j) {
-				char ctmp;
-				if (get_user(ctmp, &buf[i]))
-					return -EFAULT;
+		for (i = 0,j = k; i < count; i++,j++) {
+			char ctmp;
+			if (get_user(ctmp, &buf[i]))
+				return -EFAULT;
+			if (j && !((j+1)%9)) { /* every 9 char exept first of the file */
 				if (ctmp != '.') {
 					if (ctmp != '\n') {
 						if (op->flag & OPP_BINARY)
@@ -363,9 +365,6 @@
 					}
 				}
 			} else {
-				char ctmp;
-				if (get_user(ctmp, &buf[i]))
-					return -EFAULT;
 				if (ctmp < '0' || 
 				    (ctmp > '9' && ctmp < 'A') ||
 				    (ctmp > 'F' && ctmp < 'a') ||

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]

  reply	other threads:[~2005-01-05 15:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-03 13:08 Vincent Pelletier
2005-01-05 15:39 ` Vincent Pelletier [this message]
2005-01-05 17:25   ` [PATCH] " Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='crh1ni$v8$1@sea.gmane.org' \
    --to=subdino2004@yahoo.fr \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome