Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751699AbeANNRs (ORCPT + 1 other); Sun, 14 Jan 2018 08:17:48 -0500 Received: from mail.parknet.co.jp ([210.171.160.6]:36700 "EHLO mail.parknet.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751085AbeANNRr (ORCPT ); Sun, 14 Jan 2018 08:17:47 -0500 From: OGAWA Hirofumi To: ChenGuanqiao Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 3/3] fs: fat: add ioctl method in fat filesystem driver References: <20180110102153.12388-1-chen.chenchacha@foxmail.com> <20180110102153.12388-4-chen.chenchacha@foxmail.com> Date: Sun, 14 Jan 2018 22:17:44 +0900 In-Reply-To: <20180110102153.12388-4-chen.chenchacha@foxmail.com> (ChenGuanqiao's message of "Wed, 10 Jan 2018 18:21:53 +0800") Message-ID: <871siseg07.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 < len; ++i) { > + switch (label[i]) { > + case '0' ... '9': > + case 'A' ... 'Z': > + case '_': > + case 0x20: > + continue; I didn't check though, what windows do if label = "a b c"? (I.e. invalid name as dirent name) > +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; > + struct super_block *sb = inode->i_sb; > + char buffer[MSDOS_NAME] = {0}; Why initialize buffer? > + inode = d_inode(sb->s_root); > + > + err = fat_get_volume_label_entry(inode, &bh, &de); > + if (err) > + goto out; The dir traverse has to be had lock. > + inode_lock_shared(inode); > + memcpy(buffer, de->name, MSDOS_NAME); > + brelse(bh); > + inode_unlock_shared(inode); > + > + if (copy_to_user(vol_label, buffer, MSDOS_NAME)) > + err = -EFAULT; No issue to copy to user memory under locking. > +static int fat_ioctl_set_volume_label(struct file *file, > + u8 __user *vol_label) > +{ [...] > + err = fat_check_d_characters(label, sizeof(label)); > + if (err) > + goto out; > + > + err = mnt_want_write_file(file); > + if (err) > + goto out; > + > + down_write(&sb->s_umount); > + inode_lock(inode); BTW, lock order is tested with LOCKDEP? > + /* Synchronize the data together */ > + err = sync_dirty_buffer(boot_bh); > + if (err) > + goto out_boot_brelse; > + err = sync_dirty_buffer(vol_bh); > + if (err) > + goto out_boot_brelse; Probably, we don't need to sync vol_bh. And in the case of adding new entry, now already doesn't sync. -- OGAWA Hirofumi