On 2024/12/6 20:58, Amir Goldstein wrote:
On Fri, Dec 6, 2024 at 11:45 AM Kefeng Wang <wangkefeng.wang@xxxxxxxxxx> wrote:
...
So maybe use mm_get_unmapped_area() instead of __get_unmapped_area(),
something like below,
+static unsigned long ovl_get_unmapped_area(struct file *file,
+ unsigned long addr, unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ struct file *realfile;
+ const struct cred *old_cred;
+
+ realfile = ovl_real_file(file);
+ if (IS_ERR(realfile))
+ return PTR_ERR(realfile);
+
+ if (realfile->f_op->get_unmapped_area) {
+ unsigned long ret;
+
+ old_cred = ovl_override_creds(file_inode(file)->i_sb);
+ ret = realfile->f_op->get_unmapped_area(realfile, addr, len,
+ pgoff, flags);
+ ovl_revert_creds(old_cred);
+
+ if (ret)
+ return ret;
+ }
+
+ return mm_get_unmapped_area(current->mm, file, addr, len, pgoff,
flags);
+}
Correct me If I'm wrong.
You just need to be aware of the fact that between ovl_get_unmapped_area()
and ovl_mmap(), ovl_real_file(file) could change from the lower file, to the
upper file due to another operation that initiated copy-up.
Not sure about this part(I have very little knowledge of ovl), do you
mean that we could not use ovl_real_file()? The ovl_mmap() using
realfile = file->private_data, we may use similar way in
ovl_get_unmapped_area(). but I may have misunderstood.
Thanks.