From: Steve Dickson <SteveD@redhat.com>
To: nfs@lists.sourceforge.net
Subject: Re: [PATCH] detecting overflows in nfs_statfs
Date: Mon, 28 Jun 2004 07:20:53 -0400 [thread overview]
Message-ID: <40DFFF15.5010909@RedHat.com> (raw)
In-Reply-To: <40C74615.5070605@RedHat.com>
[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]
Steve Dickson wrote:
> Here is 2.4 patch that allows nfs_statfs() to detect values that are
> too large to deal with (i.e. > 32bit on a 32bit machine). So instead
> of returning garbage (as it does today), it returns all -1 which
> commands (like df) know how interpret. For example:
> df without the patch
>
> Filesystem 1K-blocks Used Available Use% Mounted on
> pdl585-1:/ 7108754432 -147573952589283246080 33966574080
> 101% /mnt/dl585-1
>
> df with the patch:
> Filesystem 1K-blocks Used Available Use% Mounted on
> pdl585-1:/ 1 1 1 0% /mnt/dl585-1
>
> Which should be fairly obvious that something went wrong.....
>
> Comments?
>
> Maybe this issue has already been address on the list (I know Olaf
> recently sent out a 2.6 patch) but if it hasn't.... maybe this is
> something
> Marcelo would be interested in?
>
This is an update to the previous patch that 1) always sets f_namelen
to a valid value since apps could be depending on it and 2) f_files
and f_ffree are set to -1 on any an overflows.
SteveD.
[-- Attachment #2: linux-2.4.21-nfs-eoverflow4.patch --]
[-- Type: text/plain, Size: 1662 bytes --]
--- linux-2.4.21/fs/nfs/inode.c.orig 2004-06-09 12:52:29.000000000 -0400
+++ linux-2.4.21/fs/nfs/inode.c 2004-06-16 21:14:37.000000000 -0400
@@ -593,6 +593,7 @@ out_fail:
return NULL;
}
+#define TOOBIG(_arg) ((_arg) > LONG_MAX)
static int
nfs_statfs(struct super_block *sb, struct statfs *buf)
{
@@ -605,24 +606,44 @@ nfs_statfs(struct super_block *sb, struc
error = server->rpc_ops->statfs(server, NFS_FH(sb->s_root->d_inode), &res);
buf->f_type = NFS_SUPER_MAGIC;
- if (error < 0)
+ if (error < 0) {
+ printk("nfs_statfs: statfs error = %d\n", -error);
goto out_err;
+ }
buf->f_bsize = sb->s_blocksize;
blockbits = sb->s_blocksize_bits;
blockres = (1 << blockbits) - 1;
+ buf->f_namelen = server->namelen;
+
+ /*
+ * Make sure things fit
+ */
+ if (TOOBIG(((res.tbytes + blockres) >> blockbits)))
+ goto too_big;
+ if (TOOBIG(((res.fbytes + blockres) >> blockbits)))
+ goto too_big;
+ if (TOOBIG(((res.abytes + blockres) >> blockbits)))
+ goto too_big;
+ if (TOOBIG(res.tfiles) || TOOBIG(res.afiles))
+ goto too_big;
+
buf->f_blocks = (res.tbytes + blockres) >> blockbits;
buf->f_bfree = (res.fbytes + blockres) >> blockbits;
buf->f_bavail = (res.abytes + blockres) >> blockbits;
buf->f_files = res.tfiles;
buf->f_ffree = res.afiles;
- buf->f_namelen = server->namelen;
return 0;
+
+ too_big:
+ dprintk("nfs_statfs: failed: EOVERFLOW\n");
+ buf->f_files = buf->f_ffree = -1;
+
out_err:
- printk("nfs_statfs: statfs error = %d\n", -error);
buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
return 0;
}
+#undef TOOBIG
static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
{
prev parent reply other threads:[~2004-06-28 11:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-09 17:17 [PATCH] detecting overflows in nfs_statfs Steve Dickson
2004-06-28 11:20 ` Steve Dickson [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=40DFFF15.5010909@RedHat.com \
--to=steved@redhat.com \
--cc=nfs@lists.sourceforge.net \
/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.