All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: Dave Jones <davej@redhat.com>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: filldir[64] oddness
Date: Thu, 9 Mar 2006 04:38:02 +0000	[thread overview]
Message-ID: <20060309043802.GR27946@ftp.linux.org.uk> (raw)
In-Reply-To: <20060309042744.GA23148@redhat.com>

On Wed, Mar 08, 2006 at 11:27:44PM -0500, Dave Jones wrote:
> I'm puzzled by an aparent use of uninitialised memory
> that coverity's checker picked up.
> 
> fs/readdir.c
> 
> #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
> #define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
> 
> 140  	static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
> 141  			   ino_t ino, unsigned int d_type)
> 142  	{
> 143  		struct linux_dirent __user * dirent;
> 144  		struct getdents_callback * buf = (struct getdents_callback *) __buf
> 145  		int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
> 
> How come that NAME_OFFSET isn't causing an oops when
> it dereferences stackjunk->d_name ?

It doesn't dereference it.  d_name is an array, not a pointer.  FWIW,
it should've been

#define NAME_OFFSET(de) offsetof(typeof(de), d_name)

or, better yet

#define NAME_OFFSET offsetof(struct linux_dirent, d_name)
#define NAME_OFFSET64 offsetof(struct linux_dirent64, d_name)

      parent reply	other threads:[~2006-03-09  4:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-09  4:27 filldir[64] oddness Dave Jones
2006-03-09  4:32 ` David S. Miller
2006-03-09  4:38   ` Dave Jones
2006-03-09  4:40   ` Al Viro
2006-03-09 17:02     ` Bryan O'Sullivan
2006-03-09 17:07       ` Dave Jones
2006-03-09 17:15         ` Bryan O'Sullivan
2006-03-09 17:27           ` Dave Jones
2006-03-10  1:41       ` Kyle Moffett
2006-03-10  1:44         ` Al Viro
2006-03-09  4:33 ` Vadim Lobanov
2006-03-09  4:34 ` Stephen Rothwell
2006-03-09  4:38 ` Al Viro [this message]

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=20060309043802.GR27946@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=davej@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.