From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, dave@stgolabs.net, linux-mm@kvack.org,
longman@redhat.com, manfred@colorfullife.com, mingo@redhat.com,
mm-commits@vger.kernel.org, neilb@suse.com,
oberpar@linux.ibm.com, rostedt@goodmis.org, schwab@suse.de,
stable@vger.kernel.org, torvalds@linux-foundation.org,
vvs@virtuozzo.com
Subject: [patch 5/7] ipc/util.c: sysvipc_find_ipc() incorrectly updates position index
Date: Wed, 13 May 2020 17:50:48 -0700 [thread overview]
Message-ID: <20200514005048.N5zHLNCxr%akpm@linux-foundation.org> (raw)
In-Reply-To: <20200513175005.1f4839360c18c0238df292d1@linux-foundation.org>
From: Vasily Averin <vvs@virtuozzo.com>
Subject: ipc/util.c: sysvipc_find_ipc() incorrectly updates position index
Commit 89163f93c6f9 ("ipc/util.c: sysvipc_find_ipc() should increase
position index") is causing this bug (seen on 5.6.8):
# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
# ipcmk -Q
Message queue id: 0
# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x82db8127 0 root 644 0 0
# ipcmk -Q
Message queue id: 1
# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x82db8127 0 root 644 0 0
0x76d1fb2a 1 root 644 0 0
# ipcrm -q 0
# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x76d1fb2a 1 root 644 0 0
0x76d1fb2a 1 root 644 0 0
# ipcmk -Q
Message queue id: 2
# ipcrm -q 2
# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x76d1fb2a 1 root 644 0 0
0x76d1fb2a 1 root 644 0 0
# ipcmk -Q
Message queue id: 3
# ipcrm -q 1
# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x7c982867 3 root 644 0 0
0x7c982867 3 root 644 0 0
0x7c982867 3 root 644 0 0
0x7c982867 3 root 644 0 0
Whenever an IPC item with a low id is deleted, the items with higher ids
are duplicated, as if filling a hole.
new_pos should jump through hole of unused ids, pos can be updated inside
"for" cycle.
Link: http://lkml.kernel.org/r/4921fe9b-9385-a2b4-1dc4-1099be6d2e39@virtuozzo.com
Fixes: 89163f93c6f9 ("ipc/util.c: sysvipc_find_ipc() should increase position index")
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Reported-by: Andreas Schwab <schwab@suse.de>
Acked-by: Waiman Long <longman@redhat.com>
Cc: NeilBrown <neilb@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
ipc/util.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
--- a/ipc/util.c~ipc-utilc-sysvipc_find_ipc-incorrectly-updates-position-index
+++ a/ipc/util.c
@@ -764,21 +764,21 @@ static struct kern_ipc_perm *sysvipc_fin
total++;
}
- *new_pos = pos + 1;
+ ipc = NULL;
if (total >= ids->in_use)
- return NULL;
+ goto out;
for (; pos < ipc_mni; pos++) {
ipc = idr_find(&ids->ipcs_idr, pos);
if (ipc != NULL) {
rcu_read_lock();
ipc_lock_object(ipc);
- return ipc;
+ break;
}
}
-
- /* Out of range - return NULL to terminate iteration */
- return NULL;
+out:
+ *new_pos = pos + 1;
+ return ipc;
}
static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
_
next prev parent reply other threads:[~2020-05-14 0:50 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-14 0:50 incoming Andrew Morton
2020-05-14 0:50 ` [patch 1/7] mm, memcg: fix inconsistent oom event behavior Andrew Morton
2020-05-14 0:50 ` [patch 2/7] epoll: call final ep_events_available() check under the lock Andrew Morton
2020-05-14 0:50 ` [patch 3/7] mm/gup: fix fixup_user_fault() on multiple retries Andrew Morton
2020-05-14 0:50 ` [patch 4/7] userfaultfd: fix remap event with MREMAP_DONTUNMAP Andrew Morton
2020-05-14 0:50 ` Andrew Morton [this message]
2020-05-14 0:50 ` [patch 6/7] kasan: consistently disable debugging features Andrew Morton
2020-05-14 0:50 ` [patch 7/7] kasan: add missing functions declarations to kasan.h Andrew Morton
2020-05-14 3:31 ` mmotm 2020-05-13-20-30 uploaded Andrew Morton
2020-05-14 15:30 ` mmotm 2020-05-13-20-30 uploaded (gpu/drm/bridge/sil-sii8620) Randy Dunlap
2020-05-14 15:32 ` mmotm 2020-05-13-20-30 uploaded (objtool warnings) Randy Dunlap
2020-05-14 15:33 ` Randy Dunlap
2020-05-28 15:54 ` Josh Poimboeuf
2020-05-28 17:04 ` Josh Poimboeuf
2020-05-28 17:20 ` Peter Zijlstra
2020-05-29 13:57 ` Christoph Hellwig
2020-05-29 14:35 ` Peter Zijlstra
2020-05-29 14:53 ` Peter Zijlstra
2020-05-29 15:33 ` Peter Zijlstra
2020-05-29 16:05 ` Josh Poimboeuf
2020-05-29 16:12 ` Peter Zijlstra
2020-05-29 16:50 ` Josh Poimboeuf
2020-05-29 16:54 ` Peter Zijlstra
2020-05-29 17:25 ` [PATCH] x86/uaccess: Remove redundant likely/unlikely annotations Josh Poimboeuf
2020-05-29 18:29 ` Randy Dunlap
2020-05-29 19:31 ` mmotm 2020-05-13-20-30 uploaded (objtool warnings) Linus Torvalds
2020-05-29 20:08 ` Al Viro
2020-05-29 20:14 ` Al Viro
2020-05-15 23:30 ` mmotm 2020-05-15-16-29 uploaded Andrew Morton
2020-05-16 5:53 ` Stephen Rothwell
2020-05-18 23:15 ` Stephen Rothwell
2020-05-20 4:48 ` mmotm 2020-05-19-21-47 uploaded Andrew Morton
2020-05-22 3:43 ` mmotm 2020-05-21-20-42 uploaded Andrew Morton
2020-05-22 16:26 ` mmotm 2020-05-21-20-42 uploaded (atomisp) Randy Dunlap
2020-05-23 3:36 ` mmotm 2020-05-22-20-35 uploaded Andrew Morton
2020-05-23 15:08 ` mmotm 2020-05-22-20-35 uploaded (phy/intel/phy-intel-combo.c) Randy Dunlap
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=20200514005048.N5zHLNCxr%akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=manfred@colorfullife.com \
--cc=mingo@redhat.com \
--cc=mm-commits@vger.kernel.org \
--cc=neilb@suse.com \
--cc=oberpar@linux.ibm.com \
--cc=rostedt@goodmis.org \
--cc=schwab@suse.de \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vvs@virtuozzo.com \
/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;
as well as URLs for NNTP newsgroup(s).