ovl: proper cleanup of workdir 65/307865/1
authorMiklos Szeredi <mszeredi@redhat.com>
Thu, 1 Sep 2016 09:11:59 +0000 (11:11 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 23 Feb 2024 09:04:22 +0000 (18:04 +0900)
commitb2097e1f3600e1b80fb8e5364ba862c551b0fd60
tree59644fc71653fd391d8151703c88c8a4779c5e72
parentd0c557f207f89b786b20c6928af9a74f2a702bb2
ovl: proper cleanup of workdir

commit eea2fb4851e9dcbab6b991aaf47e2e024f1f55a0 upstream.

When mounting overlayfs it needs a clean "work" directory under the
supplied workdir.

Previously the mount code removed this directory if it already existed and
created a new one.  If the removal failed (e.g. directory was not empty)
then it fell back to a read-only mount not using the workdir.

While this has never been reported, it is possible to get a non-empty
"work" dir from a previous mount of overlayfs in case of crash in the
middle of an operation using the work directory.

In this case the left over state should be discarded and the overlay
filesystem will be consistent, guaranteed by the atomicity of operations on
moving to/from the workdir to the upper layer.

This patch implements cleaning out any files left in workdir.  It is
implemented using real recursion for simplicity, but the depth is limited
to 2, because the worst case is that of a directory containing whiteouts
under "work".

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: SZ Lin (林上智) <sz.lin@moxa.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick linux-4.4.y commit 89f15c6e8212 to fix smack deny issue on overlayfs]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I34bffb51bab8ce882cf6115e5de108c838bca43f
fs/overlayfs/overlayfs.h
fs/overlayfs/readdir.c
fs/overlayfs/super.c