Received: by 10.223.185.82 with SMTP id b18csp278wrg; Thu, 8 Mar 2018 17:48:00 -0800 (PST) X-Google-Smtp-Source: AG47ELsEO2rnhTZfn/Yq7+PFSTbk+PYhoLLPyBDbZ5kycAa7vg9nh9kRJutqur6Kv0IiFID2NeII X-Received: by 2002:a17:902:6b83:: with SMTP id p3-v6mr15813990plk.25.1520560080735; Thu, 08 Mar 2018 17:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520560080; cv=none; d=google.com; s=arc-20160816; b=EZa7lJKooNu4szAu/jb2fJGwfOf0lfOHhdtvhcKOtIqeYVOG2Mzp/X8eqAR5VMVLvc 4FRjeOivpwBK5Sso3aMZw1e4a3Gq1mjer83L+4iUOUp4+jZmSmiCPmQzB27EiJyYbvqz heqMx6v48BGEyUBQje99i/3Ww0Rvehq6mL+eHNpBis7v+PheTd4UlJlJD4MlMYFcfRmH zzv1Or7hf17TzgEqJqtAo300qrO6bn4JLINwaMvAg0+KNkKxbBHshGYk0aeAIxAuyfiA 3rVIEOKlF7E8NH8ORbsXyIHcPKUfUEef9b0552srXLLTiZJNYdjIfdOh3RlE60HjXwC6 fFOw== 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 :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=yFW3Mbru4HToARb5Dl9hqfSQSbvmVfS1ZGn8w9Pbb5A=; b=YYpheCYm+Jmpq8veuhQmMg8DdfBi7avRVyBjU6diwRD1YV34SLTSj+5S2zqezX3QFm +yEfhWiI4f5X/OwG88a/IB0FIpLfKK1J7moOarlzlcLj3tU7P7mEKykSt8yHSLuH0aDe 8VwjacheBwFzYI0saKMbxeJlGORkwugJF1SwKYIbv/sWg/NJAaMcnBaMQOBoZDq1MVXS h1+LLfWaKReWZmmOojyLA7IlEuTijblbJqDgg95+VfXy9TluuaPRtPsP03Lp3sgxT4T6 P0MsLtIogxVutyYzLoYQWLB9ScI3D0+aOtIjUY/FIRDUwxIIEhO8szyi5nYaAr01hPaf 2tgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=lCc6MX22; dkim=fail header.i=@chromium.org header.s=google header.b=fC4hA1yZ; 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=fail (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 c2-v6si8155155plk.605.2018.03.08.17.47.45; Thu, 08 Mar 2018 17:48:00 -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=fail header.i=@google.com header.s=20161025 header.b=lCc6MX22; dkim=fail header.i=@chromium.org header.s=google header.b=fC4hA1yZ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751930AbeCIBqp (ORCPT + 99 others); Thu, 8 Mar 2018 20:46:45 -0500 Received: from mail-ua0-f172.google.com ([209.85.217.172]:40292 "EHLO mail-ua0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751148AbeCIBqn (ORCPT ); Thu, 8 Mar 2018 20:46:43 -0500 Received: by mail-ua0-f172.google.com with SMTP id c14so1250685uak.7 for ; Thu, 08 Mar 2018 17:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=yFW3Mbru4HToARb5Dl9hqfSQSbvmVfS1ZGn8w9Pbb5A=; b=lCc6MX22f+jRm69/ZZTvAv0sZ5IQ5VgGMoA+1GZtKrPktBuj37ksuZh/uIt+KTdonx rhL8qlBcRkBrZBuceoZy8HPWYXJTvuBZnrrmpiYnNESApYa1sLPz/SiZRTFiWZ5kHWWv SCR3xD+W62q3D68ELTn/0gQGob/jQjOW5iSPh6hNLi+bFpTVFuGqfZX/0tApx00aG2CI B8UDW/klgAOc/uwG28afPQwbZcrf5sXs9bgIccIL6l5fhgPLsBtwywfy4Td4BWMB1z7v DMfy+C5S6gjMGymFVctM3fSELtUzo/gyAseb4E6zA/bQucajDBvYSNMWUnmBPWOmf0QR QnCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=yFW3Mbru4HToARb5Dl9hqfSQSbvmVfS1ZGn8w9Pbb5A=; b=fC4hA1yZLatLu49MKC8AZi0LeVt5+1YZVyqdZh/uNp9TFcIw4LOB7PoA1va2LjRn33 7KFiuTOvKz1VW1aZILb72uLAw0aiOMY9PXPev4LmZUpRP/tt4OH4ve/dB4oNqSyFNgxQ T0ty0OGrtP2MhlZ0obrV6u7W3haQoIYpS25Bo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=yFW3Mbru4HToARb5Dl9hqfSQSbvmVfS1ZGn8w9Pbb5A=; b=WhiMQepILlH9sBNZUVJhpEng214jZNtqNG/QxNV4WlK7DPIDuFc7E259Kwa8xSo88A 0nt9+CkQs9osL1iI4r1YAz4uGUVAr5jrs7orhjQy3ay2ctR9JfY99JAR6YV76RIPoNKB e7rwK8Bz0F1LnGk80ME9EGD5n2ROTOl+GRsOGEuWXBKPdKhgVVu2wACbiWkV5eYdY87j owpai8AUsyOrrXd9j+Sc4b8/sYbMt5yy0IwEKzEtoKzZE7VirKlDuYKMCvCbAg1CJ4DE 5ch6xcVNmWAfaiIEFw2dGgnJYFcirrfNhvbWFaX2AbKGv5fVSalPwpE49Q+ixepboeWe NjQQ== X-Gm-Message-State: AElRT7GvV/fgDQw9re0Z535AXAj+sLumtlvXnNGM8G1Gs/HR2o4hZhhX dXrUpptF915vE+xLtfBL9PPeAVt8rtn1qTPUekPlCQ== X-Received: by 10.176.48.231 with SMTP id d7mr9813230uam.0.1520560002799; Thu, 08 Mar 2018 17:46:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.242.140 with HTTP; Thu, 8 Mar 2018 17:46:42 -0800 (PST) In-Reply-To: References: <20180308214045.GA6787@beast> From: Kees Cook Date: Thu, 8 Mar 2018 17:46:42 -0800 X-Google-Sender-Auth: au-k8phjW6zFhJQo9fPymaUgrzM Message-ID: Subject: Re: [PATCH] kernel.h: Skip single-eval logic on literals in min()/max() To: Linus Torvalds Cc: Andrew Morton , Josh Poimboeuf , Rasmus Villemoes , "Gustavo A. R. Silva" , "Tobin C. Harding" , Steven Rostedt , Jonathan Corbet , Chris Mason , Josef Bacik , David Sterba , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Masahiro Yamada , Borislav Petkov , Randy Dunlap , Ian Abbott , Sergey Senozhatsky , Petr Mladek , Andy Shevchenko , Pantelis Antoniou , linux-btrfs , Network Development , Linux Kernel Mailing List , Kernel Hardening 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 Thu, Mar 8, 2018 at 5:35 PM, Linus Torvalds wrote: > I don't want to weaken the type enforcement, and I _thought_ you had > done that __builtin_types_compatible_p() to keep it in place. I thought so too (that originally came from Josh), but on removal, I was surprised that the checking was retained. :) > But if that's not why you did it, then why was it there at all? If the > type warning shows through even if it's in the other expression, then > just a > > > #define __min(t1, t2, x, y) \ > __builtin_choose_expr( \ > __builtin_constant_p(x) & \ > __builtin_constant_p(y), \ > (t1)(x) < (t2)(y) ? (t1)(x) : (t2)(y), \ > __single_eval_min(t1, t2, \ > ... > > would seem to be sufficient? > > Because logically, the only thing that matters is that x and y don't > have any side effects and can be evaluated twice, and > "__builtin_constant_p()" is already a much stronger version of that. > > Hmm? The __builtin_types_compatible_p() just doesn't seem to matter > for the only thing I thought it was there for. Yup, agreed. I'll drop it. -Kees -- Kees Cook Pixel Security