Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4612192imc; Mon, 25 Feb 2019 07:55:31 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ/6NdEPlLHEL/nTDJ69hfePZzIcIgmxTrFVEMYQd+Hw2izML6ypG+z/Pp60hNIOIXGu4tk X-Received: by 2002:a63:80c7:: with SMTP id j190mr18994808pgd.357.1551110131680; Mon, 25 Feb 2019 07:55:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551110131; cv=none; d=google.com; s=arc-20160816; b=N18Q7gO/dtFZPB8gDMcLa2mF59K0WyZkR1MESyJl9KeevSD1meBFISrUPFwKqpPJYw 12S2NhbhdRt/2HAj0w2ENh55mx2ZQ+CIeBm/jaXUUrTYbe+uyf6b6xuk0cG9wTkWu9Vk Br62YlIMPO73iPqes6DQc+nJAvmGFK7yY9PITKYovcAhF6N9ED/WRT+obNvvzDPzLh77 iy8PHf5/17Z4Ig6ZmABhptMYXaVUNq9fzmAIA/z3DNJfFLaxkI4rrIZuApKY52ZF2DgO WlVIfHBtNSLqSkLgIp3SzwyS1mRPveuI9Xi2cNvfYvV0+7HoLAQHn7Dw+sLddOr+Jfre zmSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=X7sKwbYrLSIJUJ9jPqZmquG/sga/Seag9q08cTdOghg=; b=BAxhh96aLevK3e9k7jOdRA0rkAwLWjI9V91LDSKcVyEsMFujMwjvPLYfylFilXbYPq pzYzhkYhsY8Po36jNSwyYr6OBLEVQU2eP3/YNK6B1tMCoshTEumP/1UxMMfGV6H/ePB1 6Jb+dytcxxMOFhYZtOXV4ADvx+R/ei3duuJlJJgyr3+3mXJjx7EpohZ2QQ5OOw1/Y+uA 5i9S2FEb6buZJSIIgGzBaH1kApvGs8vFvyCbhVAOQUzaAjhv1ZoUK7UySb95fQPNBDsr 54obnLagubzyY0sGEDIY/8WigwNsIc8QHOx60iMd8YAtxyOahL/jbXbgx4qUyuUfMzNB z8NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=fnuF8gc0; 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 h8si9659974pls.365.2019.02.25.07.55.14; Mon, 25 Feb 2019 07:55:31 -0800 (PST) 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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=fnuF8gc0; 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 S1727814AbfBYPxS (ORCPT + 99 others); Mon, 25 Feb 2019 10:53:18 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39277 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfBYPxQ (ORCPT ); Mon, 25 Feb 2019 10:53:16 -0500 Received: by mail-wr1-f65.google.com with SMTP id l5so10496881wrw.6 for ; Mon, 25 Feb 2019 07:53:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=X7sKwbYrLSIJUJ9jPqZmquG/sga/Seag9q08cTdOghg=; b=fnuF8gc0c+N/1YCleHIqdfa6gA6JQjxj2O27uCoE6WOdS/sRJN0Ht2huTAgH2HB5Jk Jf0hIhy/SS24/DknywIbC9zl87n6GysbCHcTJGL5823X6G5M0NjI1/lTRZGeOTKtEMdx 2OvRZjShLmwytyghdSTL+IUDOzsoWiqkMuLa44T0wEBa38183NTmUclMMfOhrijqwaip RjdvlBbSb2oCaMXgo1Z/s25bbiUmkdaR912FLm+DwOqDTAXkyAFhAY6Xrzj4ru2YhPZX N8oiJOHFsz5Y55+6rPvwb+oysj8BNTqXinXDMgVA2sOTZdZeUFc8Db+LeKT7tQOX0pEG NHXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=X7sKwbYrLSIJUJ9jPqZmquG/sga/Seag9q08cTdOghg=; b=AYzBMZxEhLBRb7E+cv04aKeILKrWFz5wgDmq9/8a74X8oolta3xsx8i8OqMEHUKyg8 Wy5LFEmedf8IGnGGXixWTxeTzs87NcKSZJzXaDCxTfmExRgBz2jCjZPnDv7nvX/BrUnY y7+04lm0I1Cl/Kl+Ifai0qOTx43DODvwgyHmbvOuqZNYci8O5yRdjcz6b14bWejpKlme 3b5uGuymj/XJ6vfbiujLDBoBY58l1WHgyJ1jEvU24+XvEcfNT6mU6qYtX05XVNbE3dYW P97RRXFK417QFYf1JogWWS4QnfS0D71FCS5ou7nTV4YJevIsjgO2vErzKJpi/7dPOOQz putQ== X-Gm-Message-State: AHQUAubJmKBB/a7Mlq/nlCsUi88h2Qk5VEnHT6j2heSmHW8iQ8FWHGB3 Fa14zHb5Sga2WI9YPFElXjtrVH9hD63gTV3bwbaUKg== X-Received: by 2002:adf:e58f:: with SMTP id l15mr11960362wrm.309.1551109993843; Mon, 25 Feb 2019 07:53:13 -0800 (PST) MIME-Version: 1.0 References: <20190225124330.613028745@infradead.org> <20190225125232.191698923@infradead.org> In-Reply-To: <20190225125232.191698923@infradead.org> From: Andy Lutomirski Date: Mon, 25 Feb 2019 07:53:01 -0800 Message-ID: Subject: Re: [PATCH 5/6] objtool: Add UACCESS validation To: Peter Zijlstra Cc: Linus Torvalds , Thomas Gleixner , "H. Peter Anvin" , Julien Thierry , Will Deacon , Ingo Molnar , Catalin Marinas , James Morse , valentin.schneider@arm.com, Brian Gerst , Josh Poimboeuf , Andrew Lutomirski , Borislav Petkov , Denys Vlasenko , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 25, 2019 at 4:53 AM Peter Zijlstra wrote: > > It is important that UACCESS regions are as small as possible; > furthermore the UACCESS state is not scheduled, so doing anything that > might directly call into the scheduler will cause random code to be > ran with UACCESS enabled. > > Teach objtool too track UACCESS state and warn about any CALL made > while UACCESS is enabled. This very much includes the __fentry__() > tracing calls and __preempt_schedule() calls. > > Note that exceptions _do_ save/restore the UACCESS state, and therefore > they can drive preemption. This also means that all exception handlers > must have an otherwise dedundant UACCESS disable instruction; > therefore ignore this warning for !STT_FUNC code (exception handlers > are not normal functions). > > It also provides a UACCESS_SAFE() annotation which allows explicit > annotation. This is meant to be used for future things like: > unsafe_copy_{to,from}_user(). > > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/frame.h | 30 +++++++++++- > tools/objtool/arch.h | 4 + > tools/objtool/arch/x86/decode.c | 14 +++++ > tools/objtool/check.c | 100 ++++++++++++++++++++++++++++++++++++---- > tools/objtool/check.h | 2 > tools/objtool/elf.h | 1 > 6 files changed, 138 insertions(+), 13 deletions(-) > > --- a/include/linux/frame.h > +++ b/include/linux/frame.h > @@ -28,10 +28,38 @@ asm (".pushsection .discard.nonstd_frame > ".byte 0\n\t" > ".popsection\n\t"); > > +/* > + * This macro marks functions as UACCESS-safe, that is, it is safe to call from an > + * UACCESS enabled region (typically user_access_begin() / > + * user_access_end()). > + * > + * These functions in turn will only call UACCESS-safe functions themselves (which > + * precludes tracing, including __fentry__ and scheduling, including > + * preempt_enable). > + * > + * UACCESS-safe functions will obviously also not change UACCESS themselves. > + */ > +#define UACCESS_SAFE(func) \ > + asm (".pushsection .discard.uaccess_safe_strtab, \"S\", @3\n\t" \ > + "999: .ascii \"" #func "\"\n\t" \ > + " .byte 0\n\t" \ > + ".popsection\n\t" \ > + ".pushsection .discard.uaccess_safe\n\t" \ > + ".long 999b - .\n\t" \ > + ".popsection") Minor nit: using big numbers like 999: like this always bugs me. It relies on there not being a macro nested inside or outside this that uses the same number. My general preference is to do something like .Ldescription_\@ instead. Otherwise this looks conceptually good :)