Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp522439ybh; Wed, 15 Jul 2020 08:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNsS1iEgh5rwu5fnBvZqaNMmqBkaHZZx+3huCa+ndt1IYsV+5hgVN3yHkfFcBKU9ZkXkBy X-Received: by 2002:aa7:dad6:: with SMTP id x22mr83154eds.310.1594825897043; Wed, 15 Jul 2020 08:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594825897; cv=none; d=google.com; s=arc-20160816; b=gEiVmkYPDx8VBgK7xd9PVUp5DD4bJXOyih7NOy18nYvDNb+cLevAXxREVH/fomtAU/ 5TH/1uksHEc+Vt04xjbyKBLqjajhtd00dmxUJmFfyWgZiZbYbd6Wi229XxdH6wVwHDoy 5f2Y9vR7ik6/wD5KorqsGPg1oY83YLw3utB1g2EzwbtZoh5ge4ZjHbYi/29Tp7rLEigm yBKQp05bYOAjqEULgIBrpTBiyAYyInkzZ7m2ps79hT0oTADZD4UgsMEAftvJwNG6W+mm Nzuj82vTCJY2DDutpn5xkj3JJdsh68ADUAAKfbd/xRjKgLJVKm9O3JFJhlo75LBoMr7s YNQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=92lte8n3yu9W0SorD40v1+TSi2IDS2o0VxXIGO6eK0g=; b=jWyRh7qtXozfaJvmJkWtiniB1uaDfV0Jop31RQhAlaMc0aTARVRaekKDGKJ4KXYRqC 1e/dRFT8QGKJBX9YE1FS+PRfF5py2APDWcoJxRJdNV/YO0JzMvI4i32N+Q1TsTqtI32D qV62YUeo7j2qmVF2prkjlnd3ZO/m+0JleIhkzu1HIVG4ea+Us6IlM/QlNkBUa6QizBa2 x7F2RJ0PLDYpOhlcDLsFwN14x+hmrHQx15kjPFb0+uKz4EuBJgv390Pcg98TpO2Q9Uxm +B56r0i8anzdGZaJOXhilqaojd5bT2a/dpLw9G3aqTbWcxgy6PToyjDmzom0KMLNfvwj 0iww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bob3yeI4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si1423031eju.654.2020.07.15.08.11.14; Wed, 15 Jul 2020 08:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bob3yeI4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726848AbgGOOxD (ORCPT + 99 others); Wed, 15 Jul 2020 10:53:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32869 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726845AbgGOOxC (ORCPT ); Wed, 15 Jul 2020 10:53:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594824781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=92lte8n3yu9W0SorD40v1+TSi2IDS2o0VxXIGO6eK0g=; b=Bob3yeI4mz3GOodf1yF7IubjILiHG6BJ8qAH9d/DiB8JAaOlMtOAeNzCP8BQa81TPqAuzE xnrWN7YSJiN+QsmeZY0YwU1WhhcAFP5eAbt3JLnzbON3k0CCc9S6Sfo5VewaCZLM7kAJfq N+qIGvKTAcld+LF0z3eRiIoMKf1d5eU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-PvOYl-MuNP6OOxhtc3SWSw-1; Wed, 15 Jul 2020 10:51:54 -0400 X-MC-Unique: PvOYl-MuNP6OOxhtc3SWSw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69FB118A1DE8; Wed, 15 Jul 2020 14:51:51 +0000 (UTC) Received: from dcbz.redhat.com (ovpn-114-113.ams2.redhat.com [10.36.114.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 256A160BF1; Wed, 15 Jul 2020 14:51:47 +0000 (UTC) From: Adrian Reber To: Christian Brauner , Eric Biederman , Pavel Emelyanov , Oleg Nesterov , Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin , Nicolas Viennot , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Kamil Yurtsever , Dirk Petersen , Christine Flood , Casey Schaufler Cc: Mike Rapoport , Radostin Stoyanov , Adrian Reber , Cyrill Gorcunov , Serge Hallyn , Stephen Smalley , Sargun Dhillon , Arnd Bergmann , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, Eric Paris , Jann Horn , linux-fsdevel@vger.kernel.org Subject: [PATCH v5 5/6] prctl: Allow checkpoint/restore capable processes to change exe link Date: Wed, 15 Jul 2020 16:49:53 +0200 Message-Id: <20200715144954.1387760-6-areber@redhat.com> In-Reply-To: <20200715144954.1387760-1-areber@redhat.com> References: <20200715144954.1387760-1-areber@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Viennot Allow CAP_CHECKPOINT_RESTORE capable users to change /proc/self/exe. This commit also changes the permission error code from -EINVAL to -EPERM for consistency with the rest of the prctl() syscall when checking capabilities. Signed-off-by: Nicolas Viennot Signed-off-by: Adrian Reber --- kernel/sys.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kernel/sys.c b/kernel/sys.c index 00a96746e28a..dd59b9142b1d 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2007,12 +2007,14 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data if (prctl_map.exe_fd != (u32)-1) { /* - * Make sure the caller has the rights to - * change /proc/pid/exe link: only local sys admin should - * be allowed to. + * Check if the current user is checkpoint/restore capable. + * At the time of this writing, it checks for CAP_SYS_ADMIN + * or CAP_CHECKPOINT_RESTORE. + * Note that a user with access to ptrace can masquerade an + * arbitrary program as any executable, even setuid ones. */ - if (!ns_capable(current_user_ns(), CAP_SYS_ADMIN)) - return -EINVAL; + if (!checkpoint_restore_ns_capable(current_user_ns())) + return -EPERM; error = prctl_set_mm_exe_file(mm, prctl_map.exe_fd); if (error) -- 2.26.2