1
2
3
4
5
6
7#include <linux/fs.h>
8#include <linux/slab.h>
9#include <linux/cred.h>
10#include <linux/xattr.h>
11#include <linux/posix_acl.h>
12#include <linux/ratelimit.h>
13#include "overlayfs.h"
14
15
16int ovl_setattr(struct dentry *dentry, struct iattr *attr)
17{
18 int err;
19 bool full_copy_up = false;
20 struct dentry *upperdentry;
21 const struct cred *old_cred;
22
23 err = setattr_prepare(dentry, attr);
24 if (err)
25 return err;
26
27 err = ovl_want_write(dentry);
28 if (err)
29 goto out;
30
31 if (attr->ia_valid & ATTR_SIZE) {
32 struct inode *realinode = d_inode(ovl_dentry_real(dentry));
33
34 err = -ETXTBSY;
35 if (atomic_read(&realinode->i_writecount) < 0)
36 goto out_drop_write;
37
38
39 full_copy_up = true;
40 }
41
42 if (!full_copy_up)
43 err = ovl_copy_up(dentry);
44 else
45 err = ovl_copy_up_with_data(dentry);
46 if (!err) {
47 struct inode *winode = NULL;
48
49 upperdentry = ovl_dentry_upper(dentry);
50
51 if (attr->ia_valid & ATTR_SIZE) {
52 winode = d_inode(upperdentry);
53 err = get_write_access(winode);
54 if (err)
55 goto out_drop_write;
56 }
57
58 if (attr->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
59 attr->ia_valid &= ~ATTR_MODE;
60
61 inode_lock(upperdentry->d_inode);
62 old_cred = ovl_override_creds(dentry->d_sb);
63 err = notify_change(upperdentry, attr, NULL);
64 revert_creds(old_cred);
65 if (!err)
66 ovl_copyattr(upperdentry->d_inode, dentry->d_inode);
67 inode_unlock(upperdentry->d_inode);
68
69 if (winode)
70 put_write_access(winode);
71 }
72out_drop_write:
73 ovl_drop_write(dentry);
74out:
75 return err;
76}
77
78static int ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat,
79 struct ovl_layer *lower_layer)
80{
81 bool samefs = ovl_same_sb(dentry->d_sb);
82 unsigned int xinobits = ovl_xino_bits(dentry->d_sb);
83
84 if (samefs) {
85
86
87
88
89
90 stat->dev = dentry->d_sb->s_dev;
91 return 0;
92 } else if (xinobits) {
93 unsigned int shift = 64 - xinobits;
94
95
96
97
98
99
100
101
102 if (stat->ino >> shift) {
103 pr_warn_ratelimited("overlayfs: inode number too big (%pd2, ino=%llu, xinobits=%d)\n",
104 dentry, stat->ino, xinobits);
105 } else {
106 if (lower_layer)
107 stat->ino |= ((u64)lower_layer->fsid) << shift;
108
109 stat->dev = dentry->d_sb->s_dev;
110 return 0;
111 }
112 }
113
114
115 if (S_ISDIR(dentry->d_inode->i_mode)) {
116
117
118
119
120
121
122
123
124
125 stat->dev = dentry->d_sb->s_dev;
126 stat->ino = dentry->d_inode->i_ino;
127 } else if (lower_layer && lower_layer->fsid) {
128
129
130
131
132
133
134
135 stat->dev = lower_layer->fs->pseudo_dev;
136 }
137
138 return 0;
139}
140
141int ovl_getattr(const struct path *path, struct kstat *stat,
142 u32 request_mask, unsigned int flags)
143{
144 struct dentry *dentry = path->dentry;
145 enum ovl_path_type type;
146 struct path realpath;
147 const struct cred *old_cred;
148 bool is_dir = S_ISDIR(dentry->d_inode->i_mode);
149 bool samefs = ovl_same_sb(dentry->d_sb);
150 struct ovl_layer *lower_layer = NULL;
151 int err;
152 bool metacopy_blocks = false;
153
154 metacopy_blocks = ovl_is_metacopy_dentry(dentry);
155
156 type = ovl_path_real(dentry, &realpath);
157 old_cred = ovl_override_creds(dentry->d_sb);
158 err = vfs_getattr(&realpath, stat, request_mask, flags);
159 if (err)
160 goto out;
161
162
163
164
165
166
167
168
169
170
171 if (!is_dir || samefs || ovl_xino_bits(dentry->d_sb)) {
172 if (!OVL_TYPE_UPPER(type)) {
173 lower_layer = ovl_layer_lower(dentry);
174 } else if (OVL_TYPE_ORIGIN(type)) {
175 struct kstat lowerstat;
176 u32 lowermask = STATX_INO | STATX_BLOCKS |
177 (!is_dir ? STATX_NLINK : 0);
178
179 ovl_path_lower(dentry, &realpath);
180 err = vfs_getattr(&realpath, &lowerstat,
181 lowermask, flags);
182 if (err)
183 goto out;
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 if (ovl_test_flag(OVL_INDEX, d_inode(dentry)) ||
201 (!ovl_verify_lower(dentry->d_sb) &&
202 (is_dir || lowerstat.nlink == 1))) {
203 stat->ino = lowerstat.ino;
204 lower_layer = ovl_layer_lower(dentry);
205 }
206
207
208
209
210
211
212
213
214 if (metacopy_blocks &&
215 realpath.dentry == ovl_dentry_lowerdata(dentry)) {
216 stat->blocks = lowerstat.blocks;
217 metacopy_blocks = false;
218 }
219 }
220
221 if (metacopy_blocks) {
222
223
224
225
226 struct kstat lowerdatastat;
227 u32 lowermask = STATX_BLOCKS;
228
229 ovl_path_lowerdata(dentry, &realpath);
230 err = vfs_getattr(&realpath, &lowerdatastat,
231 lowermask, flags);
232 if (err)
233 goto out;
234 stat->blocks = lowerdatastat.blocks;
235 }
236 }
237
238 err = ovl_map_dev_ino(dentry, stat, lower_layer);
239 if (err)
240 goto out;
241
242
243
244
245
246
247 if (is_dir && OVL_TYPE_MERGE(type))
248 stat->nlink = 1;
249
250
251
252
253
254
255
256 if (!is_dir && ovl_test_flag(OVL_INDEX, d_inode(dentry)))
257 stat->nlink = dentry->d_inode->i_nlink;
258
259out:
260 revert_creds(old_cred);
261
262 return err;
263}
264
265int ovl_permission(struct inode *inode, int mask)
266{
267 struct inode *upperinode = ovl_inode_upper(inode);
268 struct inode *realinode = upperinode ?: ovl_inode_lower(inode);
269 const struct cred *old_cred;
270 int err;
271
272
273 if (!realinode) {
274 WARN_ON(!(mask & MAY_NOT_BLOCK));
275 return -ECHILD;
276 }
277
278
279
280
281
282 err = generic_permission(inode, mask);
283 if (err)
284 return err;
285
286 old_cred = ovl_override_creds(inode->i_sb);
287 if (!upperinode &&
288 !special_file(realinode->i_mode) && mask & MAY_WRITE) {
289 mask &= ~(MAY_WRITE | MAY_APPEND);
290
291 mask |= MAY_READ;
292 }
293 err = inode_permission(realinode, mask);
294 revert_creds(old_cred);
295
296 return err;
297}
298
299static const char *ovl_get_link(struct dentry *dentry,
300 struct inode *inode,
301 struct delayed_call *done)
302{
303 const struct cred *old_cred;
304 const char *p;
305
306 if (!dentry)
307 return ERR_PTR(-ECHILD);
308
309 old_cred = ovl_override_creds(dentry->d_sb);
310 p = vfs_get_link(ovl_dentry_real(dentry), done);
311 revert_creds(old_cred);
312 return p;
313}
314
315bool ovl_is_private_xattr(const char *name)
316{
317 return strncmp(name, OVL_XATTR_PREFIX,
318 sizeof(OVL_XATTR_PREFIX) - 1) == 0;
319}
320
321int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
322 const void *value, size_t size, int flags)
323{
324 int err;
325 struct dentry *upperdentry = ovl_i_dentry_upper(inode);
326 struct dentry *realdentry = upperdentry ?: ovl_dentry_lower(dentry);
327 const struct cred *old_cred;
328
329 err = ovl_want_write(dentry);
330 if (err)
331 goto out;
332
333 if (!value && !upperdentry) {
334 err = vfs_getxattr(realdentry, name, NULL, 0);
335 if (err < 0)
336 goto out_drop_write;
337 }
338
339 if (!upperdentry) {
340 err = ovl_copy_up(dentry);
341 if (err)
342 goto out_drop_write;
343
344 realdentry = ovl_dentry_upper(dentry);
345 }
346
347 old_cred = ovl_override_creds(dentry->d_sb);
348 if (value)
349 err = vfs_setxattr(realdentry, name, value, size, flags);
350 else {
351 WARN_ON(flags != XATTR_REPLACE);
352 err = vfs_removexattr(realdentry, name);
353 }
354 revert_creds(old_cred);
355
356
357 ovl_copyattr(d_inode(realdentry), inode);
358
359out_drop_write:
360 ovl_drop_write(dentry);
361out:
362 return err;
363}
364
365int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
366 void *value, size_t size)
367{
368 ssize_t res;
369 const struct cred *old_cred;
370 struct dentry *realdentry =
371 ovl_i_dentry_upper(inode) ?: ovl_dentry_lower(dentry);
372
373 old_cred = ovl_override_creds(dentry->d_sb);
374 res = vfs_getxattr(realdentry, name, value, size);
375 revert_creds(old_cred);
376 return res;
377}
378
379static bool ovl_can_list(const char *s)
380{
381
382 if (strncmp(s, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) != 0)
383 return true;
384
385
386 return !ovl_is_private_xattr(s) && capable(CAP_SYS_ADMIN);
387}
388
389ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
390{
391 struct dentry *realdentry = ovl_dentry_real(dentry);
392 ssize_t res;
393 size_t len;
394 char *s;
395 const struct cred *old_cred;
396
397 old_cred = ovl_override_creds(dentry->d_sb);
398 res = vfs_listxattr(realdentry, list, size);
399 revert_creds(old_cred);
400 if (res <= 0 || size == 0)
401 return res;
402
403
404 for (s = list, len = res; len;) {
405 size_t slen = strnlen(s, len) + 1;
406
407
408 if (WARN_ON(slen > len))
409 return -EIO;
410
411 len -= slen;
412 if (!ovl_can_list(s)) {
413 res -= slen;
414 memmove(s, s + slen, len);
415 } else {
416 s += slen;
417 }
418 }
419
420 return res;
421}
422
423struct posix_acl *ovl_get_acl(struct inode *inode, int type)
424{
425 struct inode *realinode = ovl_inode_real(inode);
426 const struct cred *old_cred;
427 struct posix_acl *acl;
428
429 if (!IS_ENABLED(CONFIG_FS_POSIX_ACL) || !IS_POSIXACL(realinode))
430 return NULL;
431
432 old_cred = ovl_override_creds(inode->i_sb);
433 acl = get_acl(realinode, type);
434 revert_creds(old_cred);
435
436 return acl;
437}
438
439int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags)
440{
441 if (flags & S_ATIME) {
442 struct ovl_fs *ofs = inode->i_sb->s_fs_info;
443 struct path upperpath = {
444 .mnt = ofs->upper_mnt,
445 .dentry = ovl_upperdentry_dereference(OVL_I(inode)),
446 };
447
448 if (upperpath.dentry) {
449 touch_atime(&upperpath);
450 inode->i_atime = d_inode(upperpath.dentry)->i_atime;
451 }
452 }
453 return 0;
454}
455
456static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
457 u64 start, u64 len)
458{
459 int err;
460 struct inode *realinode = ovl_inode_real(inode);
461 const struct cred *old_cred;
462
463 if (!realinode->i_op->fiemap)
464 return -EOPNOTSUPP;
465
466 old_cred = ovl_override_creds(inode->i_sb);
467
468 if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC)
469 filemap_write_and_wait(realinode->i_mapping);
470
471 err = realinode->i_op->fiemap(realinode, fieinfo, start, len);
472 revert_creds(old_cred);
473
474 return err;
475}
476
477static const struct inode_operations ovl_file_inode_operations = {
478 .setattr = ovl_setattr,
479 .permission = ovl_permission,
480 .getattr = ovl_getattr,
481 .listxattr = ovl_listxattr,
482 .get_acl = ovl_get_acl,
483 .update_time = ovl_update_time,
484 .fiemap = ovl_fiemap,
485};
486
487static const struct inode_operations ovl_symlink_inode_operations = {
488 .setattr = ovl_setattr,
489 .get_link = ovl_get_link,
490 .getattr = ovl_getattr,
491 .listxattr = ovl_listxattr,
492 .update_time = ovl_update_time,
493};
494
495static const struct inode_operations ovl_special_inode_operations = {
496 .setattr = ovl_setattr,
497 .permission = ovl_permission,
498 .getattr = ovl_getattr,
499 .listxattr = ovl_listxattr,
500 .get_acl = ovl_get_acl,
501 .update_time = ovl_update_time,
502};
503
504static const struct address_space_operations ovl_aops = {
505
506 .direct_IO = noop_direct_IO,
507};
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524#define OVL_MAX_NESTING FILESYSTEM_MAX_STACK_DEPTH
525
526static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
527{
528#ifdef CONFIG_LOCKDEP
529 static struct lock_class_key ovl_i_mutex_key[OVL_MAX_NESTING];
530 static struct lock_class_key ovl_i_mutex_dir_key[OVL_MAX_NESTING];
531 static struct lock_class_key ovl_i_lock_key[OVL_MAX_NESTING];
532
533 int depth = inode->i_sb->s_stack_depth - 1;
534
535 if (WARN_ON_ONCE(depth < 0 || depth >= OVL_MAX_NESTING))
536 depth = 0;
537
538 if (S_ISDIR(inode->i_mode))
539 lockdep_set_class(&inode->i_rwsem, &ovl_i_mutex_dir_key[depth]);
540 else
541 lockdep_set_class(&inode->i_rwsem, &ovl_i_mutex_key[depth]);
542
543 lockdep_set_class(&OVL_I(inode)->lock, &ovl_i_lock_key[depth]);
544#endif
545}
546
547static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev,
548 unsigned long ino, int fsid)
549{
550 int xinobits = ovl_xino_bits(inode->i_sb);
551
552
553
554
555
556
557
558
559
560
561 if (ovl_same_sb(inode->i_sb) || xinobits) {
562 inode->i_ino = ino;
563 if (xinobits && fsid && !(ino >> (64 - xinobits)))
564 inode->i_ino |= (unsigned long)fsid << (64 - xinobits);
565 } else {
566 inode->i_ino = get_next_ino();
567 }
568 inode->i_mode = mode;
569 inode->i_flags |= S_NOCMTIME;
570#ifdef CONFIG_FS_POSIX_ACL
571 inode->i_acl = inode->i_default_acl = ACL_DONT_CACHE;
572#endif
573
574 ovl_lockdep_annotate_inode_mutex_key(inode);
575
576 switch (mode & S_IFMT) {
577 case S_IFREG:
578 inode->i_op = &ovl_file_inode_operations;
579 inode->i_fop = &ovl_file_operations;
580 inode->i_mapping->a_ops = &ovl_aops;
581 break;
582
583 case S_IFDIR:
584 inode->i_op = &ovl_dir_inode_operations;
585 inode->i_fop = &ovl_dir_operations;
586 break;
587
588 case S_IFLNK:
589 inode->i_op = &ovl_symlink_inode_operations;
590 break;
591
592 default:
593 inode->i_op = &ovl_special_inode_operations;
594 init_special_inode(inode, mode, rdev);
595 break;
596 }
597}
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623#define OVL_NLINK_ADD_UPPER (1 << 0)
624
625
626
627
628
629
630
631
632static int ovl_set_nlink_common(struct dentry *dentry,
633 struct dentry *realdentry, const char *format)
634{
635 struct inode *inode = d_inode(dentry);
636 struct inode *realinode = d_inode(realdentry);
637 char buf[13];
638 int len;
639
640 len = snprintf(buf, sizeof(buf), format,
641 (int) (inode->i_nlink - realinode->i_nlink));
642
643 if (WARN_ON(len >= sizeof(buf)))
644 return -EIO;
645
646 return ovl_do_setxattr(ovl_dentry_upper(dentry),
647 OVL_XATTR_NLINK, buf, len, 0);
648}
649
650int ovl_set_nlink_upper(struct dentry *dentry)
651{
652 return ovl_set_nlink_common(dentry, ovl_dentry_upper(dentry), "U%+i");
653}
654
655int ovl_set_nlink_lower(struct dentry *dentry)
656{
657 return ovl_set_nlink_common(dentry, ovl_dentry_lower(dentry), "L%+i");
658}
659
660unsigned int ovl_get_nlink(struct dentry *lowerdentry,
661 struct dentry *upperdentry,
662 unsigned int fallback)
663{
664 int nlink_diff;
665 int nlink;
666 char buf[13];
667 int err;
668
669 if (!lowerdentry || !upperdentry || d_inode(lowerdentry)->i_nlink == 1)
670 return fallback;
671
672 err = vfs_getxattr(upperdentry, OVL_XATTR_NLINK, &buf, sizeof(buf) - 1);
673 if (err < 0)
674 goto fail;
675
676 buf[err] = '\0';
677 if ((buf[0] != 'L' && buf[0] != 'U') ||
678 (buf[1] != '+' && buf[1] != '-'))
679 goto fail;
680
681 err = kstrtoint(buf + 1, 10, &nlink_diff);
682 if (err < 0)
683 goto fail;
684
685 nlink = d_inode(buf[0] == 'L' ? lowerdentry : upperdentry)->i_nlink;
686 nlink += nlink_diff;
687
688 if (nlink <= 0)
689 goto fail;
690
691 return nlink;
692
693fail:
694 pr_warn_ratelimited("overlayfs: failed to get index nlink (%pd2, err=%i)\n",
695 upperdentry, err);
696 return fallback;
697}
698
699struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev)
700{
701 struct inode *inode;
702
703 inode = new_inode(sb);
704 if (inode)
705 ovl_fill_inode(inode, mode, rdev, 0, 0);
706
707 return inode;
708}
709
710static int ovl_inode_test(struct inode *inode, void *data)
711{
712 return inode->i_private == data;
713}
714
715static int ovl_inode_set(struct inode *inode, void *data)
716{
717 inode->i_private = data;
718 return 0;
719}
720
721static bool ovl_verify_inode(struct inode *inode, struct dentry *lowerdentry,
722 struct dentry *upperdentry, bool strict)
723{
724
725
726
727
728
729
730 if (S_ISDIR(inode->i_mode) && strict) {
731
732 if (!lowerdentry && ovl_inode_lower(inode))
733 return false;
734
735
736 if (!upperdentry && ovl_inode_upper(inode))
737 return false;
738 }
739
740
741
742
743
744
745
746 if (lowerdentry && ovl_inode_lower(inode) != d_inode(lowerdentry))
747 return false;
748
749
750
751
752
753 if (upperdentry && ovl_inode_upper(inode) != d_inode(upperdentry))
754 return false;
755
756 return true;
757}
758
759struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
760 bool is_upper)
761{
762 struct inode *inode, *key = d_inode(real);
763
764 inode = ilookup5(sb, (unsigned long) key, ovl_inode_test, key);
765 if (!inode)
766 return NULL;
767
768 if (!ovl_verify_inode(inode, is_upper ? NULL : real,
769 is_upper ? real : NULL, false)) {
770 iput(inode);
771 return ERR_PTR(-ESTALE);
772 }
773
774 return inode;
775}
776
777bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir)
778{
779 struct inode *key = d_inode(dir);
780 struct inode *trap;
781 bool res;
782
783 trap = ilookup5(sb, (unsigned long) key, ovl_inode_test, key);
784 if (!trap)
785 return false;
786
787 res = IS_DEADDIR(trap) && !ovl_inode_upper(trap) &&
788 !ovl_inode_lower(trap);
789
790 iput(trap);
791 return res;
792}
793
794
795
796
797
798
799struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir)
800{
801 struct inode *key = d_inode(dir);
802 struct inode *trap;
803
804 if (!d_is_dir(dir))
805 return ERR_PTR(-ENOTDIR);
806
807 trap = iget5_locked(sb, (unsigned long) key, ovl_inode_test,
808 ovl_inode_set, key);
809 if (!trap)
810 return ERR_PTR(-ENOMEM);
811
812 if (!(trap->i_state & I_NEW)) {
813
814 iput(trap);
815 return ERR_PTR(-ELOOP);
816 }
817
818 trap->i_mode = S_IFDIR;
819 trap->i_flags = S_DEAD;
820 unlock_new_inode(trap);
821
822 return trap;
823}
824
825
826
827
828static bool ovl_hash_bylower(struct super_block *sb, struct dentry *upper,
829 struct dentry *lower, struct dentry *index)
830{
831 struct ovl_fs *ofs = sb->s_fs_info;
832
833
834 if (!lower)
835 return false;
836
837
838 if (index)
839 return true;
840
841
842 if (!ofs->upper_mnt)
843 return true;
844
845
846 if ((upper || !ovl_indexdir(sb)) &&
847 !d_is_dir(lower) && d_inode(lower)->i_nlink > 1)
848 return false;
849
850
851 if (sb->s_export_op && upper)
852 return false;
853
854
855 return true;
856}
857
858static struct inode *ovl_iget5(struct super_block *sb, struct inode *newinode,
859 struct inode *key)
860{
861 return newinode ? inode_insert5(newinode, (unsigned long) key,
862 ovl_inode_test, ovl_inode_set, key) :
863 iget5_locked(sb, (unsigned long) key,
864 ovl_inode_test, ovl_inode_set, key);
865}
866
867struct inode *ovl_get_inode(struct super_block *sb,
868 struct ovl_inode_params *oip)
869{
870 struct dentry *upperdentry = oip->upperdentry;
871 struct ovl_path *lowerpath = oip->lowerpath;
872 struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL;
873 struct inode *inode;
874 struct dentry *lowerdentry = lowerpath ? lowerpath->dentry : NULL;
875 bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry,
876 oip->index);
877 int fsid = bylower ? oip->lowerpath->layer->fsid : 0;
878 bool is_dir, metacopy = false;
879 unsigned long ino = 0;
880 int err = oip->newinode ? -EEXIST : -ENOMEM;
881
882 if (!realinode)
883 realinode = d_inode(lowerdentry);
884
885
886
887
888
889 is_dir = S_ISDIR(realinode->i_mode);
890 if (upperdentry || bylower) {
891 struct inode *key = d_inode(bylower ? lowerdentry :
892 upperdentry);
893 unsigned int nlink = is_dir ? 1 : realinode->i_nlink;
894
895 inode = ovl_iget5(sb, oip->newinode, key);
896 if (!inode)
897 goto out_err;
898 if (!(inode->i_state & I_NEW)) {
899
900
901
902
903 if (!ovl_verify_inode(inode, lowerdentry, upperdentry,
904 true)) {
905 iput(inode);
906 err = -ESTALE;
907 goto out_err;
908 }
909
910 dput(upperdentry);
911 kfree(oip->redirect);
912 goto out;
913 }
914
915
916 if (!is_dir)
917 nlink = ovl_get_nlink(lowerdentry, upperdentry, nlink);
918 set_nlink(inode, nlink);
919 ino = key->i_ino;
920 } else {
921
922 inode = new_inode(sb);
923 if (!inode) {
924 err = -ENOMEM;
925 goto out_err;
926 }
927 }
928 ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev, ino, fsid);
929 ovl_inode_init(inode, upperdentry, lowerdentry, oip->lowerdata);
930
931 if (upperdentry && ovl_is_impuredir(upperdentry))
932 ovl_set_flag(OVL_IMPURE, inode);
933
934 if (oip->index)
935 ovl_set_flag(OVL_INDEX, inode);
936
937 if (upperdentry) {
938 err = ovl_check_metacopy_xattr(upperdentry);
939 if (err < 0)
940 goto out_err;
941 metacopy = err;
942 if (!metacopy)
943 ovl_set_flag(OVL_UPPERDATA, inode);
944 }
945
946 OVL_I(inode)->redirect = oip->redirect;
947
948 if (bylower)
949 ovl_set_flag(OVL_CONST_INO, inode);
950
951
952 if (is_dir) {
953 if (((upperdentry && lowerdentry) || oip->numlower > 1) ||
954 ovl_check_origin_xattr(upperdentry ?: lowerdentry)) {
955 ovl_set_flag(OVL_WHITEOUTS, inode);
956 }
957 }
958
959 if (inode->i_state & I_NEW)
960 unlock_new_inode(inode);
961out:
962 return inode;
963
964out_err:
965 pr_warn_ratelimited("overlayfs: failed to get inode (%i)\n", err);
966 inode = ERR_PTR(err);
967 goto out;
968}
969