The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ben Fennema <bfennema@falcon.csc.calpoly.edu>,
	Jan Kara <jack@ucw.cz>
Subject: Re: [PATCH] UDF: check for allocated memory for inode data
Date: Fri, 11 May 2007 11:49:03 +0400	[thread overview]
Message-ID: <20070511074903.GB9444@cvg> (raw)
In-Reply-To: <20070511072939.GA25727@infradead.org>

[Christoph Hellwig - Fri, May 11, 2007 at 08:29:39AM +0100]
| On Thu, May 10, 2007 at 03:46:40PM -0700, Andrew Morton wrote:
| > On Thu, 10 May 2007 18:00:00 +0400
| > Cyrill Gorcunov <gorcunov@gmail.com> wrote:
| > 
| > > This patch adds cheking for granted memory while
| > > filling up inode data to prevent possible NULL
| > > pointer usage. If there is not enough memory to
| > > fill inode data we just mark it as "bad".
| > > 
| > > Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
| > > 
| > > Please check the patch, maybe just marking inode as
| > > "bad" is not a good solution.
| > > 
| > 
| > yes, make_bad_inode() is appropriate here.
| > 
| > > 
| > > diff --git a/fs/udf/inode.c b/fs/udf/inode.c
| > > index c846155..91cddae 100644
| > > --- a/fs/udf/inode.c
| > > +++ b/fs/udf/inode.c
| > > @@ -1144,6 +1144,13 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
| > >  		UDF_I_EFE(inode) = 1;
| > >  		UDF_I_USE(inode) = 0;
| > >  		UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL);
| > > +		if (!UDF_I_DATA(inode))
| > > +		{
| > > +			printk(KERN_ERR "udf: udf_fill_inode(ino %ld) no free memory\n",
| > > +			       inode->i_ino);
| > > +			make_bad_inode(inode);
| > > +			return;
| > > +		}
| > 
| > But please let's not add three copies of identical code.  Do something like:
| > 
| > static int udf_check_inode(struct inode *inode)
| > {
| > 	if (!UDF_I_DATA(inode)) {
| > 		printk(KERN_ERR "udf: udf_fill_inode(ino %ld) no free memory\n",
| > 			inode->i_ino);
| > 		make_bad_inode(inode);
| > 		return -1;
| > 	}
| > 	return 0;
| > }
| > 
| > 
| > 	if (udf_check_inode(inode))
| > 		return;
| > 
| > In fact you can also do the kmalloc in that helper function too:
| > 
| > static int udf_alloc_i_data(struct inode *inode, size_t size)
| > {
| > 	UDF_I_DATA(inode) = kmalloc(...);
| > 	...
| > }
| 
| And please get rid of the UDF_I_* macro for everything you touch, just
| put a
| 
| 	struct udf_inode_info *uip = UDF_I(inode);
| 
| at the beginning of the function and use the fields directly.
| 

OK, I've already sent v.2 of the patch, so v.3 will become soon ;)

		Cyrill


  reply	other threads:[~2007-05-11  7:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-10 14:00 [PATCH] UDF: check for allocated memory for inode data Cyrill Gorcunov
2007-05-10 22:46 ` Andrew Morton
2007-05-11  5:52   ` Cyrill Gorcunov
2007-05-11  7:29   ` Christoph Hellwig
2007-05-11  7:49     ` Cyrill Gorcunov [this message]
2007-05-11  7:57     ` Cyrill Gorcunov
2007-05-11  9:01     ` Cyrill Gorcunov
2007-05-11 10:39       ` Christoph Hellwig
2007-05-11 11:09         ` Cyrill Gorcunov
2007-05-13 21:01           ` Christoph Hellwig
2007-05-16 14:33             ` Cyrill Gorcunov
2007-05-16 17:38               ` Jan Kara
2007-05-16 17:52                 ` Cyrill Gorcunov
2007-05-16 17:56                   ` Christoph Hellwig
2007-05-20 12:20                     ` Cyrill Gorcunov
2007-05-21  8:23                       ` Jan Kara
2007-05-21 10:36                       ` Christoph Hellwig
2007-05-12 10:09         ` Cyrill Gorcunov
2007-05-12 10:15           ` Pekka Enberg
2007-05-12 11:40             ` Cyrill Gorcunov

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=20070511074903.GB9444@cvg \
    --to=gorcunov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bfennema@falcon.csc.calpoly.edu \
    --cc=hch@infradead.org \
    --cc=jack@ucw.cz \
    --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