From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754492AbdKFSb4 (ORCPT ); Mon, 6 Nov 2017 13:31:56 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:54738 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbdKFSby (ORCPT ); Mon, 6 Nov 2017 13:31:54 -0500 X-Google-Smtp-Source: ABhQp+Rvg7UOMQTIodvrMnHo0Vn4p4/ns+CKrc5Htbjx1MTnS8eAmR/em9Sn/KglOazf9u9FTNSGCQ== From: Andrei Vagin To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Andrei Vagin , Gargi Sharma , Oleg Nesterov Subject: [PATCH v2] pid: restore the old behaviour of the ns_last_pid sysctl Date: Mon, 6 Nov 2017 10:31:44 -0800 Message-Id: <20171106183144.16368-1-avagin@openvz.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171106144733.GA19282@redhat.com> References: <20171106144733.GA19282@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CRIU uses ns_last_pid to fork a process with a specified pid. For example, if we need to create a process with the pid of 10000, we write 9999 into /proc/sys/kernel/ns_last_pid $ echo 9999 > /proc/sys/kernel/ns_last_pid; sh -c 'echo $$' 10000 This behaviour has been broken and now if we write 9999 to ns_last_pid, a process will get the pid 9999. This patch restores the old behaviour. v2: make code a bit more readable // Oleg fixes: ("pid: replace pid bitmap implementation with IDR API") Cc: Gargi Sharma Cc: Oleg Nesterov Acked-by: Oleg Nesterov Signed-off-by: Andrei Vagin --- kernel/pid_namespace.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index fea2c24fa460..0b53eef7d34b 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -287,6 +287,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write, { struct pid_namespace *pid_ns = task_active_pid_ns(current); struct ctl_table tmp = *table; + int ret, next; if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN)) return -EPERM; @@ -297,8 +298,14 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write, * it should synchronize its usage with external means. */ - tmp.data = &pid_ns->idr.idr_next; - return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); + next = idr_get_cursor(&pid_ns->idr) - 1; + + tmp.data = &next; + ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); + if (!ret && write) + idr_set_cursor(&pid_ns->idr, next + 1); + + return ret; } extern int pid_max; -- 2.13.6