From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Namjae Jeon <linkinjeon@gmail.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Ravishankar N <cyberax82@gmail.com>,
Amit Sahrawat <amit.sahrawat83@gmail.com>
Subject: Re: [PATCH] fat: Support fallocate on fat.
Date: Sun, 08 Jul 2012 22:06:56 +0900 [thread overview]
Message-ID: <87sjd2766n.fsf@devron.myhome.or.jp> (raw)
In-Reply-To: <1341716859-6768-1-git-send-email-linkinjeon@gmail.com> (Namjae Jeon's message of "Sat, 7 Jul 2012 23:07:39 -0400")
Namjae Jeon <linkinjeon@gmail.com> writes:
> +/*
> + * preallocate space for a file. This implements fat's fallocate file
> + * operation, which gets called from sys_fallocate system call. User
> + * space requests len bytes at offset.If FALLOC_FL_KEEP_SIZE is set
> + * we just allocate clusters without zeroing them out.Otherwise we
> + * allocate and zero out clusters via an expanding truncate.
> + */
> +static long fat_fallocate(struct file *file, int mode,
> + loff_t offset, loff_t len)
> +{
> + int err = 0;
> + struct inode *inode = file->f_mapping->host;
> + int cluster, nr_cluster, fclus, dclus, free_bytes, nr_bytes;
> + struct super_block *sb = inode->i_sb;
> + struct msdos_sb_info *sbi = MSDOS_SB(sb);
What happens if called for directory? And does this guarantee it never
expose the uninitialized data userland?
> + /* No support for hole punch or other fallocate flags. */
> + if (mode & ~FALLOC_FL_KEEP_SIZE)
> + return -EOPNOTSUPP;
>
> + if ((offset + len) <= MSDOS_I(inode)->mmu_private) {
> + fat_msg(sb, KERN_ERR,
> + "fat_fallocate():Blocks already allocated");
> + return -EINVAL;
> + }
Please don't output any message by user error. And EINVAL is right
behavior if (offset + len) < allocated size? Sounds like strange design.
> + if ((mode & FALLOC_FL_KEEP_SIZE)) {
> + /* First compute the number of clusters to be allocated */
> + if (inode->i_size > 0) {
> + err = fat_get_cluster(inode, FAT_ENT_EOF,
> + &fclus, &dclus);
> + if (err < 0) {
> + fat_msg(sb, KERN_ERR,
> + "fat_fallocate():fat_get_cluster() error");
Use "%s" and __func__. And looks like the error is normal
(e.g. ENOSPC), so I don't see why it needs to report.
[...]
> + /*
> + * calculate i_blocks and mmu_private from the actual number of
> + * allocated clusters instead of doing it from file size.This ensures
> + * that the preallocated disk space using FALLOC_FL_KEEP_SIZE is
> + * persistent across remounts and writes go into the allocated clusters.
> + */
> + fat_calc_dir_size(inode);
Looks like the wrong. If you didn't initialize preallocated space, the
data never be exposed to userland. It is security bug.
> inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
> & ~((loff_t)sbi->cluster_size - 1)) >> 9;
> + MSDOS_I(inode)->mmu_private = inode->i_size;
> + /* restore i_size */
> + inode->i_size = le32_to_cpu(de->size);
>
> fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
> if (sbi->options.isvfat) {
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
next prev parent reply other threads:[~2012-07-08 13:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-08 3:07 [PATCH] fat: Support fallocate on fat Namjae Jeon
2012-07-08 13:06 ` OGAWA Hirofumi [this message]
2012-07-09 6:43 ` Namjae Jeon
2012-07-09 10:55 ` OGAWA Hirofumi
2012-07-09 11:14 ` Namjae Jeon
2012-07-09 11:32 ` OGAWA Hirofumi
2012-07-11 4:22 ` Namjae Jeon
2012-07-12 10:13 ` OGAWA Hirofumi
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=87sjd2766n.fsf@devron.myhome.or.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@linux-foundation.org \
--cc=amit.sahrawat83@gmail.com \
--cc=cyberax82@gmail.com \
--cc=linkinjeon@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox