Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

UBI: add more checks to chdev open

When opening UBI volumes by their character device names, make
sure we are opening character devices, not block devices or any
other inode type.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

+8 -9
+8 -9
drivers/mtd/ubi/kapi.c
··· 291 291 */ 292 292 struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) 293 293 { 294 - int error, ubi_num, vol_id; 295 - struct ubi_volume_desc *ret; 294 + int error, ubi_num, vol_id, mod; 296 295 struct inode *inode; 297 296 struct path path; 298 297 ··· 305 306 return ERR_PTR(error); 306 307 307 308 inode = path.dentry->d_inode; 309 + mod = inode->i_mode; 308 310 ubi_num = ubi_major2num(imajor(inode)); 309 311 vol_id = iminor(inode) - 1; 310 - 311 - if (vol_id >= 0 && ubi_num >= 0) 312 - ret = ubi_open_volume(ubi_num, vol_id, mode); 313 - else 314 - ret = ERR_PTR(-ENODEV); 315 - 316 312 path_put(&path); 317 - return ret; 313 + 314 + if (!S_ISCHR(mod)) 315 + return ERR_PTR(-EINVAL); 316 + if (vol_id >= 0 && ubi_num >= 0) 317 + return ubi_open_volume(ubi_num, vol_id, mode); 318 + return ERR_PTR(-ENODEV); 318 319 } 319 320 EXPORT_SYMBOL_GPL(ubi_open_volume_path); 320 321