From: akpm@linux-foundation.org
To: mm-commits@vger.kernel.org, stable@vger.kernel.org,
ptikhomirov@virtuozzo.com, miltonm@bga.com, millerjo@us.ibm.com,
manfred@colorfullife.com, ebiederm@xmission.com,
dave@stgolabs.net, alexander@mihalicyn.com,
alexander.mikhalitsyn@virtuozzo.com
Subject: [to-be-updated] shm-skip-shm_destroy-if-task-ipc-namespace-was-changed.patch removed from -mm tree
Date: Thu, 29 Jul 2021 13:01:19 -0700 [thread overview]
Message-ID: <20210729200119.lnuxr%akpm@linux-foundation.org> (raw)
The patch titled
Subject: shm: skip shm_destroy if task IPC namespace was changed
has been removed from the -mm tree. Its filename was
shm-skip-shm_destroy-if-task-ipc-namespace-was-changed.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
Subject: shm: skip shm_destroy if task IPC namespace was changed
Patch series "shm: omit forced shm destroy if task IPC namespace was changed".
Task IPC namespace shm's has shm_rmid_forced feature which is per IPC
namespace and controlled by kernel.shm_rmid_forced sysctl. When feature
is turned on, then during task exit (and unshare(CLONE_NEWIPC)) all
sysvshm's will be destroyed by exit_shm(struct task_struct *task)
function.
But there is a problem if task was changed IPC namespace since shmget()
call. In such situation exit_shm() function will try to call
shm_destroy(<new_ipc_namespace_ptr>, <sysvshmem_from_old_ipc_namespace>)
which leads to the situation when sysvshm object still attached to old IPC
namespace but freed; later during old IPC namespace cleanup we will try to
free such sysvshm object for the second time and will get the problem :)
First patch solves this problem by postponing shm_destroy to the moment
when IPC namespace cleanup will be called. Second patch is useful to
prevent (or easy catch) such bugs in the future by adding corresponding
WARNings.
This patch (of 2):
Task may change IPC namespace by doing setns() but sysvshm objects remains
at the origin IPC namespace (=IPC namespace where task was when shmget()
was called). Let's skip forced shm destroy in such case because we can't
determine IPC namespace by shm only. These problematic sysvshm's will be
destroyed on ipc namespace cleanup.
Link: https://lkml.kernel.org/r/20210706132259.71740-1-alexander.mikhalitsyn@virtuozzo.com
Link: https://lkml.kernel.org/r/20210706132259.71740-2-alexander.mikhalitsyn@virtuozzo.com
Fixes: ab602f79915 ("shm: make exit_shm work proportional to task activity")
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
Cc: Milton Miller <miltonm@bga.com>
Cc: Jack Miller <millerjo@us.ibm.com>
Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: Alexander Mikhalitsyn <alexander@mihalicyn.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
ipc/shm.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
--- a/ipc/shm.c~shm-skip-shm_destroy-if-task-ipc-namespace-was-changed
+++ a/ipc/shm.c
@@ -173,6 +173,14 @@ static inline struct shmid_kernel *shm_o
return container_of(ipcp, struct shmid_kernel, shm_perm);
}
+static inline bool is_shm_in_ns(struct ipc_namespace *ns, struct shmid_kernel *shp)
+{
+ int idx = ipcid_to_idx(shp->shm_perm.id);
+ struct shmid_kernel *tshp = shm_obtain_object(ns, idx);
+
+ return !IS_ERR(tshp) && tshp == shp;
+}
+
/*
* shm_lock_(check_) routines are called in the paths where the rwsem
* is not necessarily held.
@@ -415,7 +423,7 @@ void exit_shm(struct task_struct *task)
list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist) {
shp->shm_creator = NULL;
- if (shm_may_destroy(ns, shp)) {
+ if (is_shm_in_ns(ns, shp) && shm_may_destroy(ns, shp)) {
shm_lock_by_ptr(shp);
shm_destroy(ns, shp);
}
_
Patches currently in -mm which might be from alexander.mikhalitsyn@virtuozzo.com are
ipc-warn-if-trying-to-remove-ipc-object-which-is-absent.patch
reply other threads:[~2021-07-29 20:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210729200119.lnuxr%akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=alexander.mikhalitsyn@virtuozzo.com \
--cc=alexander@mihalicyn.com \
--cc=dave@stgolabs.net \
--cc=ebiederm@xmission.com \
--cc=manfred@colorfullife.com \
--cc=millerjo@us.ibm.com \
--cc=miltonm@bga.com \
--cc=mm-commits@vger.kernel.org \
--cc=ptikhomirov@virtuozzo.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox