Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3529267imm; Sun, 10 Jun 2018 19:11:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJjC6a0Dv2jmbx9g6F6w1Yp183X+OSF90WGJGh9tR2zruruGtuXY2xJQdPyHee78vLTrKOq X-Received: by 2002:a17:902:6bc7:: with SMTP id m7-v6mr16444290plt.162.1528683089989; Sun, 10 Jun 2018 19:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528683089; cv=none; d=google.com; s=arc-20160816; b=q6lVDNJ2a1ITlX81DPGvj6vvegfuKXjZWz8BhwxEgEWnSnNXMD5pWsBNZv3jTCCGtp KM87TlQDO5FB/V60wI3oVzBTauk4x+gw+TBH4OKMN46qdQyt8K4rzVu/XP9ZEMYB+f2Y F9ig55WvlrIEQMKmhzJ5yHMnJLhZ+o3rNJbnm961UDXNa2SCNZRr5d5gmTc8tXfNkGS0 DLzmwI2u1zA3ici8RkMzv0tjaD6jDg44DPe1PmnaW/R1NRLfR5S5UwRktirCdIimNbP6 7S7ONZ19XsLtPdwjHHpQEdQcwrHKRNcSbeYqnAvROgIFbki8RpkK/bmfwT9Cdg/rQHBe RsXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=AIXLzcGn8Zax6VLvT9rtF7yugNPTOLq6mm4fS2+sdKA=; b=dZ/4tDigjbd6eX37M7yMXC9za0e9hJPa+KXpE9i/SD60WfTgIjV2EdRWAjXDfmfYTJ 4SmGkJYetngEJ/IYeXaX0kJ162ylVe6llGu8k8NMBFNRYdyqvJYbBx+17PKrwx4YuXAi FFQ0mHs4zjWiVAcnHYWH3j5F9SMbn2t4mQYSSHYO3yUShdEfaU+7fPxpp9zxMnnAyltZ bURu7vTRrbypORAHFQwNe6M0tMV6iZfJ5LlDugEwpOztMqxm/5EihLfpbbfTtNBwfCkm bBBB0JpSIwPGJMuUWIgeQJpBD9hFGFxPDVab3ijQpQjOjaiNSUSBW02S7PX1Emg4kCcr 2E1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g65-v6si35781120pfa.304.2018.06.10.19.11.04; Sun, 10 Jun 2018 19:11:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753866AbeFKCKc (ORCPT + 99 others); Sun, 10 Jun 2018 22:10:32 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40576 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753728AbeFKCKa (ORCPT ); Sun, 10 Jun 2018 22:10:30 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fSCHt-0005gr-11; Mon, 11 Jun 2018 02:10:29 +0000 Date: Mon, 11 Jun 2018 03:10:29 +0100 From: Al Viro To: Linus Torvalds Cc: Linux Kernel Mailing List , linux-fsdevel , Stephane Eranian Subject: perfmon trouble Message-ID: <20180611021028.GT30522@ZenIV.linux.org.uk> References: <20180608184842.GD30522@ZenIV.linux.org.uk> <20180609051051.GF30522@ZenIV.linux.org.uk> <20180609155107.GH30522@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180609155107.GH30522@ZenIV.linux.org.uk> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 09, 2018 at 04:51:08PM +0100, Al Viro wrote: > Stephane, could you comment on the situation in there? I realize that you > hadn't touched that thing in more than a decade, but I've no idea who else > might be familiar with that thing and it's very inconveniently special... Having looked through that code... ouch. It tries to have munmap-on-close, of all things. Which has interesting consequences; consider, for example, fd = perfctl(-1, PFM_CREATE_CONTEXT, &blah, 1); // create a context .... pid = fork(); if (!pid) { execve("/usr/bin/something_suid", ...); ... } with something_suid(8) doing an explicit "close each descriptor past stdout" loop. PFM_CREATE_CONTEXT has created a context, mmapped its buffer (and stored the address of that mapping in ctx->ctx_smpl_vaddr) and, having opened an associated file, sticks it into descriptor table and returns the descriptor. On fork/exec we have * descriptor table copied to child * all mappings copied to child and then destroyed by execve * execve ends up with the new binary (and libraries, etc.) mmapped (in child) Now, our careful suid-root binary does close(2) on its copy of descriptor. pfm_flush() is called. ctx->task != current, so we proceed to /* * remove virtual mapping, if any, for the calling task. * cannot reset ctx field until last user is calling close(). * * ctx_smpl_vaddr must never be cleared because it is needed * by every task with access to the context * * When called from do_exit(), the mm context is gone already, therefore * mm is NULL, i.e., the VMA is already gone and we do not have to * do anything here */ if (ctx->ctx_smpl_vaddr && current->mm) { smpl_buf_vaddr = ctx->ctx_smpl_vaddr; smpl_buf_size = ctx->ctx_smpl_size; } UNPROTECT_CTX(ctx, flags); /* * if there was a mapping, then we systematically remove it * at this point. Cannot be done inside critical section * because some VM function reenables interrupts. * */ if (smpl_buf_vaddr) pfm_remove_smpl_mapping(smpl_buf_vaddr, smpl_buf_size); ... with the last call doing vm_munmap() on the area in question. In the address space of that suid-root binary, taking out whatever *it* had mapped at that address range... I wouldn't be surprised if that turned out to be realistically exploitable ;-/ Is there any documentation of that thing's semantics? perfmonctl(2) doesn't mention the mapping at all and link to HP site in the arch/ia64/kernel/perfmon.c is 404-compliant. Playing with archive.org brings a sourceforget reference, but I hadn't been able to find anything ia64-related docs in there...