Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7431716ybi; Mon, 8 Jul 2019 21:51:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRfhZdQLg5eQAbhXl2MezuZKMPwL127KfvwSPkYOX7/spT9Mvww2CAAKVDDTCozcOeuEmQ X-Received: by 2002:a17:902:e512:: with SMTP id ck18mr27993539plb.53.1562647908834; Mon, 08 Jul 2019 21:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562647908; cv=none; d=google.com; s=arc-20160816; b=LcPZp5bBSMxVyraz+g7ZQyj+5hmrDg/M/1peMmBRmif/fmUBn5QRJoagAmFK15Vq4Z kdHCRgRkb8GyRXVJaO2ye2x0QQPR8ePtw2VQlYhGe9Ydhdt7IvVF1RJXNtfZLghQbQ0Z dQucTvk6V/fIafjJJGj878zVV/3nIl3tosJs13LZ3TY4dmwN/Mvsv4eiee+BYj2hnIbd eNj51k3WT1LPi/c1VS/K04bNucs9pj92BjYe8Qpxs076Yjo+r1a6tCGfcZtWgWO5e8vm iMod6TThsk93yafHPcbT+OltS4WLtULn8gPvio4t8wtxlb1pkIj8AJobHpqZFZrUuokV +teQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=NHGXxZKoUC+etV5J4TA2pzGAE32N1lUMWS0xtU10i5g=; b=dTXwh2qyymEqhn+hCqZjzs0Axqj2GfBpyEXRbxhVcKxalB5Y5uU7gVUb4Oa+OE9hqq 9leSRihn7UEZuMREsEMdxaA8E0Mz+19CG22Hi+zqJGgyS9Rpl39Qc6+3SO/TGku0cGpd /NthbPeOJC4pBWOtdTph0VdO+b6ne2iL767AohUGbOOwquEBUCJzJ1EG+GjJkC3GYlO8 VN54E26G8wTlz+3MiXHsxXI1EnB/hd3IOGNgeTMHkywrn0r5AhMGz9fk8j+s3gtpUx36 AK4gpqgkA0KFfD/TTCFS5TfFcMjv8kmNeUd/BF5pyIw0avP4t0vv9btfAzGTmItaByrn jZ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SagoGHLw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12si19001869plo.68.2019.07.08.21.51.33; Mon, 08 Jul 2019 21:51:48 -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; dkim=pass header.i=@chromium.org header.s=google header.b=SagoGHLw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726031AbfGIEvO (ORCPT + 99 others); Tue, 9 Jul 2019 00:51:14 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38025 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbfGIEvN (ORCPT ); Tue, 9 Jul 2019 00:51:13 -0400 Received: by mail-pg1-f196.google.com with SMTP id z75so8785621pgz.5 for ; Mon, 08 Jul 2019 21:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NHGXxZKoUC+etV5J4TA2pzGAE32N1lUMWS0xtU10i5g=; b=SagoGHLwdhyzez71wGl/CWUd7JfpmwBlosfeoAMty1PvK2lxm4NEetTyojTrzhwaud Ts1+0xOhHRFwpsMA3AASevOpJhCQpHPI498ZcCp2Qj9585GB+tRmt389Z+LWTJKx/y7s mH1FVgB0X1hwFpGEC/wHgqIXjB8rWZKfMla1I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NHGXxZKoUC+etV5J4TA2pzGAE32N1lUMWS0xtU10i5g=; b=H+PAnm0QGf8Yj5eXbf9wx45Ue5SleysCDmEczjUZiEF75Ib3XGv7NCHNwUJNYBHfnP Al78hVqtSVvDiBaiUdvJl1gVCun/VnN0cBuMRRGdYT/YPR3ojFzr86geQAeGID+CcwEU gsWvtERo+T58p+oeDQnP+je1gQ+7A9WLgC/T5W3Unsh9P55+jVDa5OS9G0bZqCV9i2Sg oBwVua05upVbIywbByaafOpfPjRKbhYoqvdjnzxYb27IQs5XoBNlmCy9QhQi0DsEVmqW KNU+9IywwJ1bdC6ypWYlED18UvwVIyqzgUKMQdM01MzoRZwa4BFbOBembfyVuuE/YQhd pLRw== X-Gm-Message-State: APjAAAWnAXAUbUknivVsUXxCBggzhX27w7sHYUg4W12hlg26I0zwTMS/ ZCuiDljeIrklT7mwVuxWFinQ5A== X-Received: by 2002:a63:7a5b:: with SMTP id j27mr28067294pgn.242.1562647873177; Mon, 08 Jul 2019 21:51:13 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n7sm23797582pff.59.2019.07.08.21.51.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2019 21:51:12 -0700 (PDT) Date: Mon, 8 Jul 2019 21:51:11 -0700 From: Kees Cook To: Salvatore Mesoraca Cc: Al Viro , linux-kernel@vger.kernel.org, Kernel Hardening , linux-mm@kvack.org, linux-security-module@vger.kernel.org, Brad Spengler , Casey Schaufler , Christoph Hellwig , Jann Horn , PaX Team , "Serge E. Hallyn" , Thomas Gleixner , James Morris Subject: Re: [PATCH v5 06/12] S.A.R.A.: WX protection Message-ID: <201907082140.51E0B9E2@keescook> References: <1562410493-8661-1-git-send-email-s.mesoraca16@gmail.com> <1562410493-8661-7-git-send-email-s.mesoraca16@gmail.com> <20190706192852.GO17978@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 07, 2019 at 05:49:35PM +0200, Salvatore Mesoraca wrote: > Al Viro wrote: > > > > On Sat, Jul 06, 2019 at 12:54:47PM +0200, Salvatore Mesoraca wrote: > > > > > +#define sara_warn_or_return(err, msg) do { \ > > > + if ((sara_wxp_flags & SARA_WXP_VERBOSE)) \ > > > + pr_wxp(msg); \ > > > + if (!(sara_wxp_flags & SARA_WXP_COMPLAIN)) \ > > > + return -err; \ > > > +} while (0) > > > + > > > +#define sara_warn_or_goto(label, msg) do { \ > > > + if ((sara_wxp_flags & SARA_WXP_VERBOSE)) \ > > > + pr_wxp(msg); \ > > > + if (!(sara_wxp_flags & SARA_WXP_COMPLAIN)) \ > > > + goto label; \ > > > +} while (0) > > > > No. This kind of "style" has no place in the kernel. > > > > Don't hide control flow. It's nasty enough to reviewers, > > but it's pure hell on anyone who strays into your code while > > chasing a bug or doing general code audit. In effect, you > > are creating your oh-so-private C dialect and assuming that > > everyone who ever looks at your code will start with learning > > that *AND* incorporating it into their mental C parser. > > I'm sorry, but you are not that important. > > > > If it looks like a function call, a casual reader will assume > > that this is exactly what it is. And when one is scanning > > through a function (e.g. to tell if handling of some kind > > of refcounts is correct, with twentieth grep through the > > tree having brought something in your code into the view), > > the last thing one wants is to switch between the area-specific > > C dialects. Simply because looking at yours is sandwiched > > between digging through some crap in drivers/target/ and that > > weird thing in kernel/tracing/, hopefully staying limited > > to 20 seconds of glancing through several functions in your > > code. > > > > Don't Do That. Really. > > I understand your concerns. > The first version of SARA didn't use these macros, > they were added because I was asked[1] to do so. > > I have absolutely no problems in reverting this change. > I just want to make sure that there is agreement on this matter. > Maybe Kees can clarify his stance. > > Thank you for your suggestions. > > [1] https://lkml.kernel.org/r/CAGXu5jJuQx2qOt_aDqDQDcqGOZ5kmr5rQ9Zjv=MRRCJ65ERfGw@mail.gmail.com I just didn't like how difficult it was to review the repeated checking. I thought then (and still think now) it's worth the unusual style to improve the immediate readability. Obviously Al disagrees. I'm not against dropping my suggestion; it's just a pain to review it and it seems like an area that would be highly prone to subtle typos. Perhaps some middle ground: #define sara_warn(msg) ({ \ if ((sara_wxp_flags & SARA_WXP_VERBOSE)) \ pr_wxp(msg); \ !(sara_wxp_flags & SARA_WXP_COMPLAIN); \ }) ... if (unlikely(sara_wxp_flags & SARA_WXP_WXORX && vm_flags & VM_WRITE && vm_flags & VM_EXEC && sara_warn("W^X"))) return -EPERM; that way the copy/pasting isn't present but the control flow is visible? -- Kees Cook