<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/overlayfs/dir.c, branch linux-4.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2021-10-27T07:32:40Z</updated>
<entry>
<title>ovl: fix missing negative dentry check in ovl_rename()</title>
<updated>2021-10-27T07:32:40Z</updated>
<author>
<name>Zheng Liang</name>
</author>
<published>2021-09-24T01:16:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a4f281ffc1d128d7ea693cbc3a796e56e919fd7c'/>
<id>urn:sha1:a4f281ffc1d128d7ea693cbc3a796e56e919fd7c</id>
<content type='text'>
commit a295aef603e109a47af355477326bd41151765b6 upstream.

The following reproducer

  mkdir lower upper work merge
  touch lower/old
  touch lower/new
  mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=work merge
  rm merge/new
  mv merge/old merge/new &amp; unlink upper/new

may result in this race:

PROCESS A:
  rename("merge/old", "merge/new");
  overwrite=true,ovl_lower_positive(old)=true,
  ovl_dentry_is_whiteout(new)=true -&gt; flags |= RENAME_EXCHANGE

PROCESS B:
  unlink("upper/new");

PROCESS A:
  lookup newdentry in new_upperdir
  call vfs_rename() with negative newdentry and RENAME_EXCHANGE

Fix by adding the missing check for negative newdentry.

Signed-off-by: Zheng Liang &lt;zhengliang6@huawei.com&gt;
Fixes: e9be9d5e76e3 ("overlay filesystem")
Cc: &lt;stable@vger.kernel.org&gt; # v3.18
Signed-off-by: Miklos Szeredi &lt;mszeredi@redhat.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Masami Ichikawa(CIP) &lt;masami.ichikawa@cybertrust.co.jp&gt;

</content>
</entry>
<entry>
<title>ovl: fix uid/gid when creating over whiteout</title>
<updated>2019-04-27T07:33:59Z</updated>
<author>
<name>Miklos Szeredi</name>
</author>
<published>2016-06-15T12:18:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=54a07fff4b217607e862b2e1e3fcec32919ad583'/>
<id>urn:sha1:54a07fff4b217607e862b2e1e3fcec32919ad583</id>
<content type='text'>
[ Upstream commit d0e13f5bbe4be7c8f27736fc40503dcec04b7de0 ]

Fix a regression when creating a file over a whiteout.  The new
file/directory needs to use the current fsuid/fsgid, not the ones from the
mounter's credentials.

The refcounting is a bit tricky: prepare_creds() sets an original refcount,
override_creds() gets one more, which revert_cred() drops.  So

  1) we need to expicitly put the mounter's credentials when overriding
     with the updated one

  2) we need to put the original ref to the updated creds (and this can
     safely be done before revert_creds(), since we'll still have the ref
     from override_creds()).

Reported-by: Stephen Smalley &lt;sds@tycho.nsa.gov&gt;
Fixes: 3fe6e52f0626 ("ovl: override creds with the ones from the superblock mounter")
Signed-off-by: Miklos Szeredi &lt;mszeredi@redhat.com&gt;
Signed-off-by: Sasha Levin (Microsoft) &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>ovl: override creds with the ones from the superblock mounter</title>
<updated>2018-09-15T07:40:41Z</updated>
<author>
<name>Antonio Murdaca</name>
</author>
<published>2016-04-07T13:48:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=121b09d30d48a59a0ae621b130f3b4e42e724e68'/>
<id>urn:sha1:121b09d30d48a59a0ae621b130f3b4e42e724e68</id>
<content type='text'>
commit 3fe6e52f062643676eb4518d68cee3bc1272091b upstream.

In user namespace the whiteout creation fails with -EPERM because the
current process isn't capable(CAP_SYS_ADMIN) when setting xattr.

A simple reproducer:

$ mkdir upper lower work merged lower/dir
$ sudo mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=work merged
$ unshare -m -p -f -U -r bash

Now as root in the user namespace:

\# touch merged/dir/{1,2,3} # this will force a copy up of lower/dir
\# rm -fR merged/*

This ends up failing with -EPERM after the files in dir has been
correctly deleted:

unlinkat(4, "2", 0)                     = 0
unlinkat(4, "1", 0)                     = 0
unlinkat(4, "3", 0)                     = 0
close(4)                                = 0
unlinkat(AT_FDCWD, "merged/dir", AT_REMOVEDIR) = -1 EPERM (Operation not
permitted)

Interestingly, if you don't place files in merged/dir you can remove it,
meaning if upper/dir does not exist, creating the char device file works
properly in that same location.

This patch uses ovl_sb_creator_cred() to get the cred struct from the
superblock mounter and override the old cred with these new ones so that
the whiteout creation is possible because overlay is wrong in assuming that
the creds it will get with prepare_creds will be in the initial user
namespace.  The old cap_raise game is removed in favor of just overriding
the old cred struct.

This patch also drops from ovl_copy_up_one() the following two lines:

override_cred-&gt;fsuid = stat-&gt;uid;
override_cred-&gt;fsgid = stat-&gt;gid;

This is because the correct uid and gid are taken directly with the stat
struct and correctly set with ovl_set_attr().

Signed-off-by: Antonio Murdaca &lt;runcom@redhat.com&gt;
Signed-off-by: Miklos Szeredi &lt;mszeredi@redhat.com&gt;
Signed-off-by: SZ Lin (林上智) &lt;sz.lin@moxa.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>ovl: Fix info leak in ovl_lookup_temp()</title>
<updated>2016-10-28T07:01:30Z</updated>
<author>
<name>Richard Weinberger</name>
</author>
<published>2016-09-16T09:45:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0a5600d83fa5a251c91459779d5311a005e4c5b3'/>
<id>urn:sha1:0a5600d83fa5a251c91459779d5311a005e4c5b3</id>
<content type='text'>
commit 6a45b3628ce4dcf7498b39c87d475bab6e2a9b24 upstream.

The function uses the memory address of a struct dentry as unique id.
While the address-based directory entry is only visible to root it is IMHO
still worth fixing since the temporary name does not have to be a kernel
address.  It can be any unique number.  Replace it by an atomic integer
which is allowed to wrap around.

Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Signed-off-by: Miklos Szeredi &lt;mszeredi@redhat.com&gt;
Fixes: e9be9d5e76e3 ("overlay filesystem")
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>ovl: verify upper dentry before unlink and rename</title>
<updated>2016-07-27T16:47:40Z</updated>
<author>
<name>Miklos Szeredi</name>
</author>
<published>2016-03-21T16:31:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dbf72a4d4531e7e5fb28e76d902d66f05c1bfe12'/>
<id>urn:sha1:dbf72a4d4531e7e5fb28e76d902d66f05c1bfe12</id>
<content type='text'>
commit 11f3710417d026ea2f4fcf362d866342c5274185 upstream.

Unlink and rename in overlayfs checked the upper dentry for staleness by
verifying upper-&gt;d_parent against upperdir.  However the dentry can go
stale also by being unhashed, for example.

Expand the verification to actually look up the name again (under parent
lock) and check if it matches the upper dentry.  This matches what the VFS
does before passing the dentry to filesytem's unlink/rename methods, which
excludes any inconsistency caused by overlayfs.

Signed-off-by: Miklos Szeredi &lt;mszeredi@redhat.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>ovl: verify upper dentry in ovl_remove_and_whiteout()</title>
<updated>2016-07-27T16:47:39Z</updated>
<author>
<name>Maxim Patlasov</name>
</author>
<published>2016-07-22T01:24:26Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cf2a2c6de0516f595825c9c46eb8ebc12a48dd31'/>
<id>urn:sha1:cf2a2c6de0516f595825c9c46eb8ebc12a48dd31</id>
<content type='text'>
commit cfc9fde0b07c3b44b570057c5f93dda59dca1c94 upstream.

The upper dentry may become stale before we call ovl_lock_rename_workdir.
For example, someone could (mistakenly or maliciously) manually unlink(2)
it directly from upperdir.

To ensure it is not stale, let's lookup it after ovl_lock_rename_workdir
and and check if it matches the upper dentry.

Essentially, it is the same problem and similar solution as in
commit 11f3710417d0 ("ovl: verify upper dentry before unlink and rename").

Signed-off-by: Maxim Patlasov &lt;mpatlasov@virtuozzo.com&gt;
Signed-off-by: Miklos Szeredi &lt;mszeredi@redhat.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>ovl: fix getcwd() failure after unsuccessful rmdir</title>
<updated>2016-03-16T15:43:01Z</updated>
<author>
<name>Rui Wang</name>
</author>
<published>2016-01-08T15:09:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2f639e2e95ea8c06f287f768bc17d03d43480d0d'/>
<id>urn:sha1:2f639e2e95ea8c06f287f768bc17d03d43480d0d</id>
<content type='text'>
commit ce9113bbcbf45a57c082d6603b9a9f342be3ef74 upstream.

ovl_remove_upper() should do d_drop() only after it successfully
removes the dir, otherwise a subsequent getcwd() system call will
fail, breaking userspace programs.

This is to fix: https://bugzilla.kernel.org/show_bug.cgi?id=110491

Signed-off-by: Rui Wang &lt;rui.y.wang@intel.com&gt;
Reviewed-by: Konstantin Khlebnikov &lt;koct9i@gmail.com&gt;
Signed-off-by: Miklos Szeredi &lt;miklos@szeredi.hu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;


</content>
</entry>
<entry>
<title>ovl: ignore lower entries when checking purity of non-directory entries</title>
<updated>2016-03-16T15:42:59Z</updated>
<author>
<name>Konstantin Khlebnikov</name>
</author>
<published>2016-01-31T13:17:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e25cdcefedc43f0e633866a526bc1ba2dd13d32e'/>
<id>urn:sha1:e25cdcefedc43f0e633866a526bc1ba2dd13d32e</id>
<content type='text'>
commit 45d11738969633ec07ca35d75d486bf2d8918df6 upstream.

After rename file dentry still holds reference to lower dentry from
previous location. This doesn't matter for data access because data comes
from upper dentry. But this stale lower dentry taints dentry at new
location and turns it into non-pure upper. Such file leaves visible
whiteout entry after remove in directory which shouldn't have whiteouts at
all.

Overlayfs already tracks pureness of file location in oe-&gt;opaque.  This
patch just uses that for detecting actual path type.

Comment from Vivek Goyal's patch:

Here are the details of the problem. Do following.

$ mkdir upper lower work merged upper/dir/
$ touch lower/test
$ sudo mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=
work merged
$ mv merged/test merged/dir/
$ rm merged/dir/test
$ ls -l merged/dir/
/usr/bin/ls: cannot access merged/dir/test: No such file or directory
total 0
c????????? ? ? ? ?            ? test

Basic problem seems to be that once a file has been unlinked, a whiteout
has been left behind which was not needed and hence it becomes visible.

Whiteout is visible because parent dir is of not type MERGE, hence
od-&gt;is_real is set during ovl_dir_open(). And that means ovl_iterate()
passes on iterate handling directly to underlying fs. Underlying fs does
not know/filter whiteouts so it becomes visible to user.

Why did we leave a whiteout to begin with when we should not have.
ovl_do_remove() checks for OVL_TYPE_PURE_UPPER() and does not leave
whiteout if file is pure upper. In this case file is not found to be pure
upper hence whiteout is left.

So why file was not PURE_UPPER in this case? I think because dentry is
still carrying some leftover state which was valid before rename. For
example, od-&gt;numlower was set to 1 as it was a lower file. After rename,
this state is not valid anymore as there is no such file in lower.

Signed-off-by: Konstantin Khlebnikov &lt;koct9i@gmail.com&gt;
Reported-by: Viktor Stanchev &lt;me@viktorstanchev.com&gt;
Suggested-by: Vivek Goyal &lt;vgoyal@redhat.com&gt;
Link: https://bugzilla.kernel.org/show_bug.cgi?id=109611
Acked-by: Vivek Goyal &lt;vgoyal@redhat.com&gt;
Signed-off-by: Miklos Szeredi &lt;miklos@szeredi.hu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>ovl: mount read-only if workdir can't be created</title>
<updated>2015-05-19T12:30:12Z</updated>
<author>
<name>Miklos Szeredi</name>
</author>
<published>2015-05-19T12:30:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cc6f67bcafcb6bbbb2d1be1603dcd95125a52800'/>
<id>urn:sha1:cc6f67bcafcb6bbbb2d1be1603dcd95125a52800</id>
<content type='text'>
OpenWRT folks reported that overlayfs fails to mount if upper fs is full,
because workdir can't be created.  Wordir creation can fail for various
other reasons too.

There's no reason that the mount itself should fail, overlayfs can work
fine without a workdir, as long as the overlay isn't modified.

So mount it read-only and don't allow remounting read-write.

Add a couple of WARN_ON()s for the impossible case of workdir being used
despite being read-only.

Reported-by: Bastian Bittorf &lt;bittorf@bluebottle.com&gt; 
Signed-off-by: Miklos Szeredi &lt;mszeredi@suse.cz&gt;
Cc: &lt;stable@vger.kernel.org&gt; # v3.18+
</content>
</entry>
<entry>
<title>ovl: don't remove non-empty opaque directory</title>
<updated>2015-05-14T08:04:44Z</updated>
<author>
<name>Miklos Szeredi</name>
</author>
<published>2015-05-14T08:04:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d377c5eb54dd05aeb3094b7740252d19ba7791f7'/>
<id>urn:sha1:d377c5eb54dd05aeb3094b7740252d19ba7791f7</id>
<content type='text'>
When removing an opaque directory we can't just call rmdir() to check for
emptiness, because the directory will need to be replaced with a whiteout.
The replacement is done with RENAME_EXCHANGE, which doesn't check
emptiness.

Solution is just to check emptiness by reading the directory.  In the
future we could add a new rename flag to check for emptiness even for
RENAME_EXCHANGE to optimize this case.

Reported-by: Vincent Batts &lt;vbatts@gmail.com&gt;
Signed-off-by: Miklos Szeredi &lt;mszeredi@suse.cz&gt;
Tested-by: Jordi Pujol Palomer &lt;jordipujolp@gmail.com&gt;
Fixes: 263b4a0fee43 ("ovl: dont replace opaque dir")
Cc: &lt;stable@vger.kernel.org&gt; # v4.0+
</content>
</entry>
</feed>
