From patchwork Wed Jul 15 14:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Reber X-Patchwork-Id: 11665607 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9409F17C7 for ; Wed, 15 Jul 2020 14:53:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C240206E9 for ; Wed, 15 Jul 2020 14:53:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bob3yeI4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbgGOOxD (ORCPT ); Wed, 15 Jul 2020 10:53:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:24889 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726846AbgGOOxC (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?b?TWljaGHFgiBDxYJh?= =?utf-8?b?cGnFhHNraQ==?= , 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 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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)