original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1596 lines
40 KiB

fs: Limit sys_mount to only request filesystem modules. Modify the request_module to prefix the file system type with "fs-" and add aliases to all of the filesystems that can be built as modules to match. A common practice is to build all of the kernel code and leave code that is not commonly needed as modules, with the result that many users are exposed to any bug anywhere in the kernel. Looking for filesystems with a fs- prefix limits the pool of possible modules that can be loaded by mount to just filesystems trivially making things safer with no real cost. Using aliases means user space can control the policy of which filesystem modules are auto-loaded by editing /etc/modprobe.d/*.conf with blacklist and alias directives. Allowing simple, safe, well understood work-arounds to known problematic software. This also addresses a rare but unfortunate problem where the filesystem name is not the same as it's module name and module auto-loading would not work. While writing this patch I saw a handful of such cases. The most significant being autofs that lives in the module autofs4. This is relevant to user namespaces because we can reach the request module in get_fs_type() without having any special permissions, and people get uncomfortable when a user specified string (in this case the filesystem type) goes all of the way to request_module. After having looked at this issue I don't think there is any particular reason to perform any filtering or permission checks beyond making it clear in the module request that we want a filesystem module. The common pattern in the kernel is to call request_module() without regards to the users permissions. In general all a filesystem module does once loaded is call register_filesystem() and go to sleep. Which means there is not much attack surface exposed by loading a filesytem module unless the filesystem is mounted. In a user namespace filesystems are not mounted unless .fs_flags = FS_USERNS_MOUNT, which most filesystems do not set today. Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Acked-by: Kees Cook <keescook@chromium.org> Reported-by: Kees Cook <keescook@google.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
9 years ago
  1. /*
  2. * linux/fs/isofs/inode.c
  3. *
  4. * (C) 1991 Linus Torvalds - minix filesystem
  5. * 1992, 1993, 1994 Eric Youngdale Modified for ISO 9660 filesystem.
  6. * 1994 Eberhard Mönkeberg - multi session handling.
  7. * 1995 Mark Dobie - allow mounting of some weird VideoCDs and PhotoCDs.
  8. * 1997 Gordon Chaffee - Joliet CDs
  9. * 1998 Eric Lammerts - ISO 9660 Level 3
  10. * 2004 Paul Serice - Inode Support pushed out from 4GB to 128GB
  11. * 2004 Paul Serice - NFS Export Operations
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/nls.h>
  17. #include <linux/ctype.h>
  18. #include <linux/statfs.h>
  19. #include <linux/cdrom.h>
  20. #include <linux/parser.h>
  21. #include <linux/mpage.h>
  22. #include <linux/user_namespace.h>
  23. #include "isofs.h"
  24. #include "zisofs.h"
  25. #define BEQUIET
  26. static int isofs_hashi(const struct dentry *parent, const struct inode *inode,
  27. struct qstr *qstr);
  28. static int isofs_hash(const struct dentry *parent, const struct inode *inode,
  29. struct qstr *qstr);
  30. static int isofs_dentry_cmpi(const struct dentry *parent,
  31. const struct inode *pinode,
  32. const struct dentry *dentry, const struct inode *inode,
  33. unsigned int len, const char *str, const struct qstr *name);
  34. static int isofs_dentry_cmp(const struct dentry *parent,
  35. const struct inode *pinode,
  36. const struct dentry *dentry, const struct inode *inode,
  37. unsigned int len, const char *str, const struct qstr *name);
  38. #ifdef CONFIG_JOLIET
  39. static int isofs_hashi_ms(const struct dentry *parent, const struct inode *inode,
  40. struct qstr *qstr);
  41. static int isofs_hash_ms(const struct dentry *parent, const struct inode *inode,
  42. struct qstr *qstr);
  43. static int isofs_dentry_cmpi_ms(const struct dentry *parent,
  44. const struct inode *pinode,
  45. const struct dentry *dentry, const struct inode *inode,
  46. unsigned int len, const char *str, const struct qstr *name);
  47. static int isofs_dentry_cmp_ms(const struct dentry *parent,
  48. const struct inode *pinode,
  49. const struct dentry *dentry, const struct inode *inode,
  50. unsigned int len, const char *str, const struct qstr *name);
  51. #endif
  52. static void isofs_put_super(struct super_block *sb)
  53. {
  54. struct isofs_sb_info *sbi = ISOFS_SB(sb);
  55. #ifdef CONFIG_JOLIET
  56. unload_nls(sbi->s_nls_iocharset);
  57. #endif
  58. kfree(sbi);
  59. sb->s_fs_info = NULL;
  60. return;
  61. }
  62. static int isofs_read_inode(struct inode *);
  63. static int isofs_statfs (struct dentry *, struct kstatfs *);
  64. static struct kmem_cache *isofs_inode_cachep;
  65. static struct inode *isofs_alloc_inode(struct super_block *sb)
  66. {
  67. struct iso_inode_info *ei;
  68. ei = kmem_cache_alloc(isofs_inode_cachep, GFP_KERNEL);
  69. if (!ei)
  70. return NULL;
  71. return &ei->vfs_inode;
  72. }
  73. static void isofs_i_callback(struct rcu_head *head)
  74. {
  75. struct inode *inode = container_of(head, struct inode, i_rcu);
  76. kmem_cache_free(isofs_inode_cachep, ISOFS_I(inode));
  77. }
  78. static void isofs_destroy_inode(struct inode *inode)
  79. {
  80. call_rcu(&inode->i_rcu, isofs_i_callback);
  81. }
  82. static void init_once(void *foo)
  83. {
  84. struct iso_inode_info *ei = foo;
  85. inode_init_once(&ei->vfs_inode);
  86. }
  87. static int init_inodecache(void)
  88. {
  89. isofs_inode_cachep = kmem_cache_create("isofs_inode_cache",
  90. sizeof(struct iso_inode_info),
  91. 0, (SLAB_RECLAIM_ACCOUNT|
  92. SLAB_MEM_SPREAD),
  93. init_once);
  94. if (isofs_inode_cachep == NULL)
  95. return -ENOMEM;
  96. return 0;
  97. }
  98. static void destroy_inodecache(void)
  99. {
  100. /*
  101. * Make sure all delayed rcu free inodes are flushed before we
  102. * destroy cache.
  103. */
  104. rcu_barrier();
  105. kmem_cache_destroy(isofs_inode_cachep);
  106. }
  107. static int isofs_remount(struct super_block *sb, int *flags, char *data)
  108. {
  109. /* we probably want a lot more here */
  110. *flags |= MS_RDONLY;
  111. return 0;
  112. }
  113. static const struct super_operations isofs_sops = {
  114. .alloc_inode = isofs_alloc_inode,
  115. .destroy_inode = isofs_destroy_inode,
  116. .put_super = isofs_put_super,
  117. .statfs = isofs_statfs,
  118. .remount_fs = isofs_remount,
  119. .show_options = generic_show_options,
  120. };
  121. static const struct dentry_operations isofs_dentry_ops[] = {
  122. {
  123. .d_hash = isofs_hash,
  124. .d_compare = isofs_dentry_cmp,
  125. },
  126. {
  127. .d_hash = isofs_hashi,
  128. .d_compare = isofs_dentry_cmpi,
  129. },
  130. #ifdef CONFIG_JOLIET
  131. {
  132. .d_hash = isofs_hash_ms,
  133. .d_compare = isofs_dentry_cmp_ms,
  134. },
  135. {
  136. .d_hash = isofs_hashi_ms,
  137. .d_compare = isofs_dentry_cmpi_ms,
  138. },
  139. #endif
  140. };
  141. struct iso9660_options{
  142. unsigned int rock:1;
  143. unsigned int joliet:1;
  144. unsigned int cruft:1;
  145. unsigned int hide:1;
  146. unsigned int showassoc:1;
  147. unsigned int nocompress:1;
  148. unsigned int overriderockperm:1;
  149. unsigned int uid_set:1;
  150. unsigned int gid_set:1;
  151. unsigned int utf8:1;
  152. unsigned char map;
  153. unsigned char check;
  154. unsigned int blocksize;
  155. umode_t fmode;
  156. umode_t dmode;
  157. kgid_t gid;
  158. kuid_t uid;
  159. char *iocharset;
  160. /* LVE */
  161. s32 session;
  162. s32 sbsector;
  163. };
  164. /*
  165. * Compute the hash for the isofs name corresponding to the dentry.
  166. */
  167. static int
  168. isofs_hash_common(const struct dentry *dentry, struct qstr *qstr, int ms)
  169. {
  170. const char *name;
  171. int len;
  172. len = qstr->len;
  173. name = qstr->name;
  174. if (ms) {
  175. while (len && name[len-1] == '.')
  176. len--;
  177. }
  178. qstr->hash = full_name_hash(name, len);
  179. return 0;
  180. }
  181. /*
  182. * Compute the hash for the isofs name corresponding to the dentry.
  183. */
  184. static int
  185. isofs_hashi_common(const struct dentry *dentry, struct qstr *qstr, int ms)
  186. {
  187. const char *name;
  188. int len;
  189. char c;
  190. unsigned long hash;
  191. len = qstr->len;
  192. name = qstr->name;
  193. if (ms) {
  194. while (len && name[len-1] == '.')
  195. len--;
  196. }
  197. hash = init_name_hash();
  198. while (len--) {
  199. c = tolower(*name++);
  200. hash = partial_name_hash(c, hash);
  201. }
  202. qstr->hash = end_name_hash(hash);
  203. return 0;
  204. }
  205. /*
  206. * Compare of two isofs names.
  207. */
  208. static int isofs_dentry_cmp_common(
  209. unsigned int len, const char *str,
  210. const struct qstr *name, int ms, int ci)
  211. {
  212. int alen, blen;
  213. /* A filename cannot end in '.' or we treat it like it has none */
  214. alen = name->len;
  215. blen = len;
  216. if (ms) {
  217. while (alen && name->name[alen-1] == '.')
  218. alen--;
  219. while (blen && str[blen-1] == '.')
  220. blen--;
  221. }
  222. if (alen == blen) {
  223. if (ci) {
  224. if (strnicmp(name->name, str, alen) == 0)
  225. return 0;
  226. } else {
  227. if (strncmp(name->name, str, alen) == 0)
  228. return 0;
  229. }
  230. }
  231. return 1;
  232. }
  233. static int
  234. isofs_hash(const struct dentry *dentry, const struct inode *inode,
  235. struct qstr *qstr)
  236. {
  237. return isofs_hash_common(dentry, qstr, 0);
  238. }
  239. static int
  240. isofs_hashi(const struct dentry *dentry, const struct inode *inode,
  241. struct qstr *qstr)
  242. {
  243. return isofs_hashi_common(dentry, qstr, 0);
  244. }
  245. static int
  246. isofs_dentry_cmp(const struct dentry *parent, const struct inode *pinode,
  247. const struct dentry *dentry, const struct inode *inode,
  248. unsigned int len, const char *str, const struct qstr *name)
  249. {
  250. return isofs_dentry_cmp_common(len, str, name, 0, 0);
  251. }
  252. static int
  253. isofs_dentry_cmpi(const struct dentry *parent, const struct inode *pinode,
  254. const struct dentry *dentry, const struct inode *inode,
  255. unsigned int len, const char *str, const struct qstr *name)
  256. {
  257. return isofs_dentry_cmp_common(len, str, name, 0, 1);
  258. }
  259. #ifdef CONFIG_JOLIET
  260. static int
  261. isofs_hash_ms(const struct dentry *dentry, const struct inode *inode,
  262. struct qstr *qstr)
  263. {
  264. return isofs_hash_common(dentry, qstr, 1);
  265. }
  266. static int
  267. isofs_hashi_ms(const struct dentry *dentry, const struct inode *inode,
  268. struct qstr *qstr)
  269. {
  270. return isofs_hashi_common(dentry, qstr, 1);
  271. }
  272. static int
  273. isofs_dentry_cmp_ms(const struct dentry *parent, const struct inode *pinode,
  274. const struct dentry *dentry, const struct inode *inode,
  275. unsigned int len, const char *str, const struct qstr *name)
  276. {
  277. return isofs_dentry_cmp_common(len, str, name, 1, 0);
  278. }
  279. static int
  280. isofs_dentry_cmpi_ms(const struct dentry *parent, const struct inode *pinode,
  281. const struct dentry *dentry, const struct inode *inode,
  282. unsigned int len, const char *str, const struct qstr *name)
  283. {
  284. return isofs_dentry_cmp_common(len, str, name, 1, 1);
  285. }
  286. #endif
  287. enum {
  288. Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore,
  289. Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet,
  290. Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err,
  291. Opt_nocompress, Opt_hide, Opt_showassoc, Opt_dmode, Opt_overriderockperm,
  292. };
  293. static const match_table_t tokens = {
  294. {Opt_norock, "norock"},
  295. {Opt_nojoliet, "nojoliet"},
  296. {Opt_unhide, "unhide"},
  297. {Opt_hide, "hide"},
  298. {Opt_showassoc, "showassoc"},
  299. {Opt_cruft, "cruft"},
  300. {Opt_utf8, "utf8"},
  301. {Opt_iocharset, "iocharset=%s"},
  302. {Opt_map_a, "map=acorn"},
  303. {Opt_map_a, "map=a"},
  304. {Opt_map_n, "map=normal"},
  305. {Opt_map_n, "map=n"},
  306. {Opt_map_o, "map=off"},
  307. {Opt_map_o, "map=o"},
  308. {Opt_session, "session=%u"},
  309. {Opt_sb, "sbsector=%u"},
  310. {Opt_check_r, "check=relaxed"},
  311. {Opt_check_r, "check=r"},
  312. {Opt_check_s, "check=strict"},
  313. {Opt_check_s, "check=s"},
  314. {Opt_uid, "uid=%u"},
  315. {Opt_gid, "gid=%u"},
  316. {Opt_mode, "mode=%u"},
  317. {Opt_dmode, "dmode=%u"},
  318. {Opt_overriderockperm, "overriderockperm"},
  319. {Opt_block, "block=%u"},
  320. {Opt_ignore, "conv=binary"},
  321. {Opt_ignore, "conv=b"},
  322. {Opt_ignore, "conv=text"},
  323. {Opt_ignore, "conv=t"},
  324. {Opt_ignore, "conv=mtext"},
  325. {Opt_ignore, "conv=m"},
  326. {Opt_ignore, "conv=auto"},
  327. {Opt_ignore, "conv=a"},
  328. {Opt_nocompress, "nocompress"},
  329. {Opt_err, NULL}
  330. };
  331. static int parse_options(char *options, struct iso9660_options *popt)
  332. {
  333. char *p;
  334. int option;
  335. popt->map = 'n';
  336. popt->rock = 1;
  337. popt->joliet = 1;
  338. popt->cruft = 0;
  339. popt->hide = 0;
  340. popt->showassoc = 0;
  341. popt->check = 'u'; /* unset */
  342. popt->nocompress = 0;
  343. popt->blocksize = 1024;
  344. popt->fmode = popt->dmode = ISOFS_INVALID_MODE;
  345. popt->uid_set = 0;
  346. popt->gid_set = 0;
  347. popt->gid = GLOBAL_ROOT_GID;
  348. popt->uid = GLOBAL_ROOT_UID;
  349. popt->iocharset = NULL;
  350. popt->utf8 = 0;
  351. popt->overriderockperm = 0;
  352. popt->session=-1;
  353. popt->sbsector=-1;
  354. if (!options)
  355. return 1;
  356. while ((p = strsep(&options, ",")) != NULL) {
  357. int token;
  358. substring_t args[MAX_OPT_ARGS];
  359. unsigned n;
  360. if (!*p)
  361. continue;
  362. token = match_token(p, tokens, args);
  363. switch (token) {
  364. case Opt_norock:
  365. popt->rock = 0;
  366. break;
  367. case Opt_nojoliet:
  368. popt->joliet = 0;
  369. break;
  370. case Opt_hide:
  371. popt->hide = 1;
  372. break;
  373. case Opt_unhide:
  374. case Opt_showassoc:
  375. popt->showassoc = 1;
  376. break;
  377. case Opt_cruft:
  378. popt->cruft = 1;
  379. break;
  380. case Opt_utf8:
  381. popt->utf8 = 1;
  382. break;
  383. #ifdef CONFIG_JOLIET
  384. case Opt_iocharset:
  385. popt->iocharset = match_strdup(&args[0]);
  386. break;
  387. #endif
  388. case Opt_map_a:
  389. popt->map = 'a';
  390. break;
  391. case Opt_map_o:
  392. popt->map = 'o';
  393. break;
  394. case Opt_map_n:
  395. popt->map = 'n';
  396. break;
  397. case Opt_session:
  398. if (match_int(&args[0], &option))
  399. return 0;
  400. n = option;
  401. if (n > 99)
  402. return 0;
  403. popt->session = n + 1;
  404. break;
  405. case Opt_sb:
  406. if (match_int(&args[0], &option))
  407. return 0;
  408. popt->sbsector = option;
  409. break;
  410. case Opt_check_r:
  411. popt->check = 'r';
  412. break;
  413. case Opt_check_s:
  414. popt->check = 's';
  415. break;
  416. case Opt_ignore:
  417. break;
  418. case Opt_uid:
  419. if (match_int(&args[0], &option))
  420. return 0;
  421. popt->uid = make_kuid(current_user_ns(), option);
  422. if (!uid_valid(popt->uid))
  423. return 0;
  424. popt->uid_set = 1;
  425. break;
  426. case Opt_gid:
  427. if (match_int(&args[0], &option))
  428. return 0;
  429. popt->gid = make_kgid(current_user_ns(), option);
  430. if (!gid_valid(popt->gid))
  431. return 0;
  432. popt->gid_set = 1;
  433. break;
  434. case Opt_mode:
  435. if (match_int(&args[0], &option))
  436. return 0;
  437. popt->fmode = option;
  438. break;
  439. case Opt_dmode:
  440. if (match_int(&args[0], &option))
  441. return 0;
  442. popt->dmode = option;
  443. break;
  444. case Opt_overriderockperm:
  445. popt->overriderockperm = 1;
  446. break;
  447. case Opt_block:
  448. if (match_int(&args[0], &option))
  449. return 0;
  450. n = option;
  451. if (n != 512 && n != 1024 && n != 2048)
  452. return 0;
  453. popt->blocksize = n;
  454. break;
  455. case Opt_nocompress:
  456. popt->nocompress = 1;
  457. break;
  458. default:
  459. return 0;
  460. }
  461. }
  462. return 1;
  463. }
  464. /*
  465. * look if the driver can tell the multi session redirection value
  466. *
  467. * don't change this if you don't know what you do, please!
  468. * Multisession is legal only with XA disks.
  469. * A non-XA disk with more than one volume descriptor may do it right, but
  470. * usually is written in a nowhere standardized "multi-partition" manner.
  471. * Multisession uses absolute addressing (solely the first frame of the whole
  472. * track is #0), multi-partition uses relative addressing (each first frame of
  473. * each track is #0), and a track is not a session.
  474. *
  475. * A broken CDwriter software or drive firmware does not set new standards,
  476. * at least not if conflicting with the existing ones.
  477. *
  478. * emoenke@gwdg.de
  479. */
  480. #define WE_OBEY_THE_WRITTEN_STANDARDS 1
  481. static unsigned int isofs_get_last_session(struct super_block *sb, s32 session)
  482. {
  483. struct cdrom_multisession ms_info;
  484. unsigned int vol_desc_start;
  485. struct block_device *bdev = sb->s_bdev;
  486. int i;
  487. vol_desc_start=0;
  488. ms_info.addr_format=CDROM_LBA;
  489. if(session >= 0 && session <= 99) {
  490. struct cdrom_tocentry Te;
  491. Te.cdte_track=session;
  492. Te.cdte_format=CDROM_LBA;
  493. i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te);
  494. if (!i) {
  495. printk(KERN_DEBUG "ISOFS: Session %d start %d type %d\n",
  496. session, Te.cdte_addr.lba,
  497. Te.cdte_ctrl&CDROM_DATA_TRACK);
  498. if ((Te.cdte_ctrl&CDROM_DATA_TRACK) == 4)
  499. return Te.cdte_addr.lba;
  500. }
  501. printk(KERN_ERR "ISOFS: Invalid session number or type of track\n");
  502. }
  503. i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info);
  504. if (session > 0)
  505. printk(KERN_ERR "ISOFS: Invalid session number\n");
  506. #if 0
  507. printk(KERN_DEBUG "isofs.inode: CDROMMULTISESSION: rc=%d\n",i);
  508. if (i==0) {
  509. printk(KERN_DEBUG "isofs.inode: XA disk: %s\n",ms_info.xa_flag?"yes":"no");
  510. printk(KERN_DEBUG "isofs.inode: vol_desc_start = %d\n", ms_info.addr.lba);
  511. }
  512. #endif
  513. if (i==0)
  514. #if WE_OBEY_THE_WRITTEN_STANDARDS
  515. if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
  516. #endif
  517. vol_desc_start=ms_info.addr.lba;
  518. return vol_desc_start;
  519. }
  520. /*
  521. * Check if root directory is empty (has less than 3 files).
  522. *
  523. * Used to detect broken CDs where ISO root directory is empty but Joliet root
  524. * directory is OK. If such CD has Rock Ridge extensions, they will be disabled
  525. * (and Joliet used instead) or else no files would be visible.
  526. */
  527. static bool rootdir_empty(struct super_block *sb, unsigned long block)
  528. {
  529. int offset = 0, files = 0, de_len;
  530. struct iso_directory_record *de;
  531. struct buffer_head *bh;
  532. bh = sb_bread(sb, block);
  533. if (!bh)
  534. return true;
  535. while (files < 3) {
  536. de = (struct iso_directory_record *) (bh->b_data + offset);
  537. de_len = *(unsigned char *) de;
  538. if (de_len == 0)
  539. break;
  540. files++;
  541. offset += de_len;
  542. }
  543. brelse(bh);
  544. return files < 3;
  545. }
  546. /*
  547. * Initialize the superblock and read the root inode.
  548. *
  549. * Note: a check_disk_change() has been done immediately prior
  550. * to this call, so we don't need to check again.
  551. */
  552. static int isofs_fill_super(struct super_block *s, void *data, int silent)
  553. {
  554. struct buffer_head *bh = NULL, *pri_bh = NULL;
  555. struct hs_primary_descriptor *h_pri = NULL;
  556. struct iso_primary_descriptor *pri = NULL;
  557. struct iso_supplementary_descriptor *sec = NULL;
  558. struct iso_directory_record *rootp;
  559. struct inode *inode;
  560. struct iso9660_options opt;
  561. struct isofs_sb_info *sbi;
  562. unsigned long first_data_zone;
  563. int joliet_level = 0;
  564. int iso_blknum, block;
  565. int orig_zonesize;
  566. int table, error = -EINVAL;
  567. unsigned int vol_desc_start;
  568. save_mount_options(s, data);
  569. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  570. if (!sbi)
  571. return -ENOMEM;
  572. s->s_fs_info = sbi;
  573. if (!parse_options((char *)data, &opt))
  574. goto out_freesbi;
  575. /*
  576. * First of all, get the hardware blocksize for this device.
  577. * If we don't know what it is, or the hardware blocksize is
  578. * larger than the blocksize the user specified, then use
  579. * that value.
  580. */
  581. /*
  582. * What if bugger tells us to go beyond page size?
  583. */
  584. opt.blocksize = sb_min_blocksize(s, opt.blocksize);
  585. sbi->s_high_sierra = 0; /* default is iso9660 */
  586. vol_desc_start = (opt.sbsector != -1) ?
  587. opt.sbsector : isofs_get_last_session(s,opt.session);
  588. for (iso_blknum = vol_desc_start+16;
  589. iso_blknum < vol_desc_start+100; iso_blknum++) {
  590. struct hs_volume_descriptor *hdp;
  591. struct iso_volume_descriptor *vdp;
  592. block = iso_blknum << (ISOFS_BLOCK_BITS - s->s_blocksize_bits);
  593. if (!(bh = sb_bread(s, block)))
  594. goto out_no_read;
  595. vdp = (struct iso_volume_descriptor *)bh->b_data;
  596. hdp = (struct hs_volume_descriptor *)bh->b_data;
  597. /*
  598. * Due to the overlapping physical location of the descriptors,
  599. * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure
  600. * proper identification in this case, we first check for ISO.
  601. */
  602. if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) {
  603. if (isonum_711(vdp->type) == ISO_VD_END)
  604. break;
  605. if (isonum_711(vdp->type) == ISO_VD_PRIMARY) {
  606. if (pri == NULL) {
  607. pri = (struct iso_primary_descriptor *)vdp;
  608. /* Save the buffer in case we need it ... */
  609. pri_bh = bh;
  610. bh = NULL;
  611. }
  612. }
  613. #ifdef CONFIG_JOLIET
  614. else if (isonum_711(vdp->type) == ISO_VD_SUPPLEMENTARY) {
  615. sec = (struct iso_supplementary_descriptor *)vdp;
  616. if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) {
  617. if (opt.joliet) {
  618. if (sec->escape[2] == 0x40)
  619. joliet_level = 1;
  620. else if (sec->escape[2] == 0x43)
  621. joliet_level = 2;
  622. else if (sec->escape[2] == 0x45)
  623. joliet_level = 3;
  624. printk(KERN_DEBUG "ISO 9660 Extensions: "
  625. "Microsoft Joliet Level %d\n",
  626. joliet_level);
  627. }
  628. goto root_found;
  629. } else {
  630. /* Unknown supplementary volume descriptor */
  631. sec = NULL;
  632. }
  633. }
  634. #endif
  635. } else {
  636. if (strncmp (hdp->id, HS_STANDARD_ID, sizeof hdp->id) == 0) {
  637. if (isonum_711(hdp->type) != ISO_VD_PRIMARY)
  638. goto out_freebh;
  639. sbi->s_high_sierra = 1;
  640. opt.rock = 0;
  641. h_pri = (struct hs_primary_descriptor *)vdp;
  642. goto root_found;
  643. }
  644. }
  645. /* Just skip any volume descriptors we don't recognize */
  646. brelse(bh);
  647. bh = NULL;
  648. }
  649. /*
  650. * If we fall through, either no volume descriptor was found,
  651. * or else we passed a primary descriptor looking for others.
  652. */
  653. if (!pri)
  654. goto out_unknown_format;
  655. brelse(bh);
  656. bh = pri_bh;
  657. pri_bh = NULL;
  658. root_found:
  659. if (joliet_level && (pri == NULL || !opt.rock)) {
  660. /* This is the case of Joliet with the norock mount flag.
  661. * A disc with both Joliet and Rock Ridge is handled later
  662. */
  663. pri = (struct iso_primary_descriptor *) sec;
  664. }
  665. if(sbi->s_high_sierra){
  666. rootp = (struct iso_directory_record *) h_pri->root_directory_record;
  667. sbi->s_nzones = isonum_733(h_pri->volume_space_size);
  668. sbi->s_log_zone_size = isonum_723(h_pri->logical_block_size);
  669. sbi->s_max_size = isonum_733(h_pri->volume_space_size);
  670. } else {
  671. if (!pri)
  672. goto out_freebh;
  673. rootp = (struct iso_directory_record *) pri->root_directory_record;
  674. sbi->s_nzones = isonum_733(pri->volume_space_size);
  675. sbi->s_log_zone_size = isonum_723(pri->logical_block_size);
  676. sbi->s_max_size = isonum_733(pri->volume_space_size);
  677. }
  678. sbi->s_ninodes = 0; /* No way to figure this out easily */
  679. orig_zonesize = sbi->s_log_zone_size;
  680. /*
  681. * If the zone size is smaller than the hardware sector size,
  682. * this is a fatal error. This would occur if the disc drive
  683. * had sectors that were 2048 bytes, but the filesystem had
  684. * blocks that were 512 bytes (which should only very rarely
  685. * happen.)
  686. */
  687. if (orig_zonesize < opt.blocksize)
  688. goto out_bad_size;
  689. /* RDE: convert log zone size to bit shift */
  690. switch (sbi->s_log_zone_size) {
  691. case 512: sbi->s_log_zone_size = 9; break;
  692. case 1024: sbi->s_log_zone_size = 10; break;
  693. case 2048: sbi->s_log_zone_size = 11; break;
  694. default:
  695. goto out_bad_zone_size;
  696. }
  697. s->s_magic = ISOFS_SUPER_MAGIC;
  698. /*
  699. * With multi-extent files, file size is only limited by the maximum
  700. * size of a file system, which is 8 TB.
  701. */
  702. s->s_maxbytes = 0x80000000000LL;
  703. /*
  704. * The CDROM is read-only, has no nodes (devices) on it, and since
  705. * all of the files appear to be owned by root, we really do not want
  706. * to allow suid. (suid or devices will not show up unless we have
  707. * Rock Ridge extensions)
  708. */
  709. s->s_flags |= MS_RDONLY /* | MS_NODEV | MS_NOSUID */;
  710. /* Set this for reference. Its not currently used except on write
  711. which we don't have .. */
  712. first_data_zone = isonum_733(rootp->extent) +
  713. isonum_711(rootp->ext_attr_length);
  714. sbi->s_firstdatazone = first_data_zone;
  715. #ifndef BEQUIET
  716. printk(KERN_DEBUG "ISOFS: Max size:%ld Log zone size:%ld\n",
  717. sbi->s_max_size, 1UL << sbi->s_log_zone_size);
  718. printk(KERN_DEBUG "ISOFS: First datazone:%ld\n", sbi->s_firstdatazone);
  719. if(sbi->s_high_sierra)
  720. printk(KERN_DEBUG "ISOFS: Disc in High Sierra format.\n");
  721. #endif
  722. /*
  723. * If the Joliet level is set, we _may_ decide to use the
  724. * secondary descriptor, but can't be sure until after we
  725. * read the root inode. But before reading the root inode
  726. * we may need to change the device blocksize, and would
  727. * rather release the old buffer first. So, we cache the
  728. * first_data_zone value from the secondary descriptor.
  729. */
  730. if (joliet_level) {
  731. pri = (struct iso_primary_descriptor *) sec;
  732. rootp = (struct iso_directory_record *)
  733. pri->root_directory_record;
  734. first_data_zone = isonum_733(rootp->extent) +
  735. isonum_711(rootp->ext_attr_length);
  736. }
  737. /*
  738. * We're all done using the volume descriptor, and may need
  739. * to change the device blocksize, so release the buffer now.
  740. */
  741. brelse(pri_bh);
  742. brelse(bh);
  743. /*
  744. * Force the blocksize to 512 for 512 byte sectors. The file
  745. * read primitives really get it wrong in a bad way if we don't
  746. * do this.
  747. *
  748. * Note - we should never be setting the blocksize to something
  749. * less than the hardware sector size for the device. If we
  750. * do, we would end up having to read larger buffers and split
  751. * out portions to satisfy requests.
  752. *
  753. * Note2- the idea here is that we want to deal with the optimal
  754. * zonesize in the filesystem. If we have it set to something less,
  755. * then we have horrible problems with trying to piece together
  756. * bits of adjacent blocks in order to properly read directory
  757. * entries. By forcing the blocksize in this way, we ensure
  758. * that we will never be required to do this.
  759. */
  760. sb_set_blocksize(s, orig_zonesize);
  761. sbi->s_nls_iocharset = NULL;
  762. #ifdef CONFIG_JOLIET
  763. if (joliet_level && opt.utf8 == 0) {
  764. char *p = opt.iocharset ? opt.iocharset : CONFIG_NLS_DEFAULT;
  765. sbi->s_nls_iocharset = load_nls(p);
  766. if (! sbi->s_nls_iocharset) {
  767. /* Fail only if explicit charset specified */
  768. if (opt.iocharset)
  769. goto out_freesbi;
  770. sbi->s_nls_iocharset = load_nls_default();
  771. }
  772. }
  773. #endif
  774. s->s_op = &isofs_sops;
  775. s->s_export_op = &isofs_export_ops;
  776. sbi->s_mapping = opt.map;
  777. sbi->s_rock = (opt.rock ? 2 : 0);
  778. sbi->s_rock_offset = -1; /* initial offset, will guess until SP is found*/
  779. sbi->s_cruft = opt.cruft;
  780. sbi->s_hide = opt.hide;
  781. sbi->s_showassoc = opt.showassoc;
  782. sbi->s_uid = opt.uid;
  783. sbi->s_gid = opt.gid;
  784. sbi->s_uid_set = opt.uid_set;
  785. sbi->s_gid_set = opt.gid_set;
  786. sbi->s_utf8 = opt.utf8;
  787. sbi->s_nocompress = opt.nocompress;
  788. sbi->s_overriderockperm = opt.overriderockperm;
  789. /*
  790. * It would be incredibly stupid to allow people to mark every file
  791. * on the disk as suid, so we merely allow them to set the default
  792. * permissions.
  793. */
  794. if (opt.fmode != ISOFS_INVALID_MODE)
  795. sbi->s_fmode = opt.fmode & 0777;
  796. else
  797. sbi->s_fmode = ISOFS_INVALID_MODE;
  798. if (opt.dmode != ISOFS_INVALID_MODE)
  799. sbi->s_dmode = opt.dmode & 0777;
  800. else
  801. sbi->s_dmode = ISOFS_INVALID_MODE;
  802. /*
  803. * Read the root inode, which _may_ result in changing
  804. * the s_rock flag. Once we have the final s_rock value,
  805. * we then decide whether to use the Joliet descriptor.
  806. */
  807. inode = isofs_iget(s, sbi->s_firstdatazone, 0);
  808. if (IS_ERR(inode))
  809. goto out_no_root;
  810. /*
  811. * Fix for broken CDs with Rock Ridge and empty ISO root directory but
  812. * correct Joliet root directory.
  813. */
  814. if (sbi->s_rock == 1 && joliet_level &&
  815. rootdir_empty(s, sbi->s_firstdatazone)) {
  816. printk(KERN_NOTICE
  817. "ISOFS: primary root directory is empty. "
  818. "Disabling Rock Ridge and switching to Joliet.");
  819. sbi->s_rock = 0;
  820. }
  821. /*
  822. * If this disk has both Rock Ridge and Joliet on it, then we
  823. * want to use Rock Ridge by default. This can be overridden
  824. * by using the norock mount option. There is still one other
  825. * possibility that is not taken into account: a Rock Ridge
  826. * CD with Unicode names. Until someone sees such a beast, it
  827. * will not be supported.
  828. */
  829. if (sbi->s_rock == 1) {
  830. joliet_level = 0;
  831. } else if (joliet_level) {
  832. sbi->s_rock = 0;
  833. if (sbi->s_firstdatazone != first_data_zone) {
  834. sbi->s_firstdatazone = first_data_zone;
  835. printk(KERN_DEBUG
  836. "ISOFS: changing to secondary root\n");
  837. iput(inode);
  838. inode = isofs_iget(s, sbi->s_firstdatazone, 0);
  839. if (IS_ERR(inode))