Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757681AbeAIILB (ORCPT + 1 other); Tue, 9 Jan 2018 03:11:01 -0500 Received: from mail.parknet.co.jp ([210.171.160.6]:36073 "EHLO mail.parknet.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754742AbeAIILA (ORCPT ); Tue, 9 Jan 2018 03:11:00 -0500 From: OGAWA Hirofumi To: ChenGuanqiao Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 3/3] fs: fat: add ioctl method in fat filesystem driver References: <20180102064229.25202-1-chen.chenchacha@foxmail.com> <20180102064229.25202-4-chen.chenchacha@foxmail.com> Date: Tue, 09 Jan 2018 17:10:57 +0900 In-Reply-To: <20180102064229.25202-4-chen.chenchacha@foxmail.com> (ChenGuanqiao's message of "Tue, 2 Jan 2018 14:42:29 +0800") Message-ID: <87lgh7e9ke.fsf@mail.parknet.co.jp> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: ChenGuanqiao writes: > +static int fat_check_d_characters(char *label, unsigned long len) > +{ > + int i; > + > + for (i=0; i + switch (label[i]) { > + case '0' ... '9': > + case 'A' ... 'Z': > + case '_': > + continue; > + case 0x20: > + return 0; Hm, stop check at ' '? What if "aaa b.%%%"? > +static int fat_ioctl_get_volume_label(struct inode *inode, > + u8 __user *vol_label) > +{ > + int err = 0; > + struct buffer_head *bh; > + struct msdos_dir_entry *de; Hm, user has to care to open rootdir for this ioctl? Isn't it better to force use the root inode? > + inode_lock_shared(inode); > + err = fat_scan_volume_label(inode, &bh, &de); > + if (err) > + goto out; > + > + if (copy_to_user(vol_label, de->name, MSDOS_NAME)) > + err = -EFAULT; Better to copy to user buffer outside locking. > +static int fat_ioctl_set_volume_label(struct file *file, > + u8 __user *vol_label) > +{ > + int err = 0; > + u8 label[MSDOS_NAME]; > + struct buffer_head *boot_bh; > + struct buffer_head *vol_bh; > + struct msdos_dir_entry *de; > + struct fat_boot_sector *b; > + struct inode *inode = file_inode(file); > + struct super_block *sb = inode->i_sb; > + struct msdos_sb_info *sbi = MSDOS_SB(sb); > + > + if (inode->i_ino != MSDOS_ROOT_INO) { Same with above, better to force use the root inode. > + down_write(&sb->s_umount); > + inode_lock(inode); > + > + /* Updates root directory's vol_label */ > + err = fat_scan_volume_label(inode, &vol_bh, &de); > + if (err) { > + /* Create volume label entry */ > + struct timespec ts; > + > + mutex_lock(&sbi->s_lock); No need sbi->s_lock? > + ts = current_time(inode); > + err = fat_add_volume_label_entry(inode, label, &ts); > + mutex_unlock(&sbi->s_lock); > + > + if (err) > + goto out_vol_brelse; > + } else { > + /* Write to root directory */ > + lock_buffer(vol_bh); No need lock_buffer()? > + memcpy(de->name, label, sizeof(de->name)); Probably, update timestamp? > + mark_buffer_dirty(vol_bh); > + unlock_buffer(vol_bh); > + } > + > + /* Update sector's vol_label */ > + boot_bh = sb_bread(sb, 0); > + if (boot_bh == NULL) { > + fat_msg(sb, KERN_ERR, > + "unable to read boot sector to write volume label"); > + err = -EIO; > + goto out_boot_brelse; > + } > + > + b = (struct fat_boot_sector *)boot_bh->b_data; > + lock_buffer(boot_bh); No need lock_buffer()? > + if (sbi->fat_bits == 32) > + memcpy(b->fat32.vol_label, label, sizeof(label)); > + else > + memcpy(b->fat16.vol_label, label, sizeof(label)); > + > + mark_buffer_dirty(boot_bh); > + unlock_buffer(boot_bh); -- OGAWA Hirofumi