[Devel] [PATCH RHEL COMMIT] ipc: WARN if trying to remove ipc object which is absent

Konstantin Khorenko khorenko at virtuozzo.com
Fri Oct 1 19:38:36 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 0c73478fe3ca49d00d8d6ec778a7483b2f5c3042
Author: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
Date:   Fri Oct 1 19:38:36 2021 +0300

    ipc: WARN if trying to remove ipc object which is absent
    
    Lets produce a warning if we trying to remove non-existing
    IPC object from IPC namespace kht/idr structures.
    
    This allows to catch possible bugs when ipc_rmid() function was
    called with inconsistent struct ipc_ids*, struct kern_ipc_perm*
    arguments.
    
    https://jira.sw.ru/browse/PSBM-131142
    
    Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
    
    (cherry-picked from vz8 commit b4c1aa46c142 ("ipc: WARN if trying
    to remove ipc object which is absent"))
    
    Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 ipc/util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ipc/util.c b/ipc/util.c
index 963945a9d2e9..d5732e62c8c3 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -447,8 +447,8 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
 static void ipc_kht_remove(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
 {
 	if (ipcp->key != IPC_PRIVATE)
-		rhashtable_remove_fast(&ids->key_ht, &ipcp->khtnode,
-				       ipc_kht_params);
+		WARN_ON(rhashtable_remove_fast(&ids->key_ht, &ipcp->khtnode,
+				       ipc_kht_params));
 }
 
 /**
@@ -498,7 +498,7 @@ void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
 {
 	int idx = ipcid_to_idx(ipcp->id);
 
-	idr_remove(&ids->ipcs_idr, idx);
+	WARN_ON(idr_remove(&ids->ipcs_idr, idx) != ipcp);
 	ipc_kht_remove(ids, ipcp);
 	ids->in_use--;
 	ipcp->deleted = true;


More information about the Devel mailing list