Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1700612ybb; Fri, 29 Mar 2019 09:31:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzUiUszrLmEdnwtojXDI1MgDwvekE9ylq+iH1bMgb5j/nGFvRtBidms5hDQeOQeA/qQBTb X-Received: by 2002:a62:e518:: with SMTP id n24mr29336094pff.174.1553877112938; Fri, 29 Mar 2019 09:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553877112; cv=none; d=google.com; s=arc-20160816; b=DXZs2ZNbt71kjZ3nuhifGTEl2Vz9VOh8O3y7Bkig3ptCTPvf1j5CXka34SJb/KNoDm HOA14OdqCLYx2nqtmsGs91cdhpuxe2m+obQ+fBMLd6OPgHnIOpBh7/mYzQVHU06ybc1W LWCMKtsImnAHuJnOmhP9y/1lLVELybllHGmfurH/udBYhbCNBx7OjvLkS3y2smFgdaes V8TwqgRV6i52KFPdsAy2njCSNv1mot0TYQIMyRzPCjrN3EKpwPrQCgmQq28jg017F8T2 zbrzgFQejL9SCzETDoAa0vxKL7OaNUmJG5NPaQcgYpTCXX1tmOr3PKBCi+KM9S/J8Sd1 Z5zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=Lju3Sh2kmpmmLQeEIQ2kymRMSnNvrQCfL6/ZPFgSoEI=; b=0Q9SGKMbp61k8PgfeCeiKtO8Zf7Vy0QTI7NCLiW4MCBd/6nM3AbTbmH1iQTPiB0T5R PGTwk3zTmcTyvtkICIf85U3YZnZYPWundjUlin5EklOmOtKHc0XIxQsRbQ9DjQTmQkCd 10wkovoJTQJE8Ge9beToj7aK3eHw6PERw3U5cx3r+omTdvIsyhC8vhdokDdYXCdcl0rx UQX+wGQlvbBBqt1RfeRblB/FjW7nuwtPSxXsMimagxKaPZaCEIybiQuLXOfnMuq7m3g4 XQcGNbhSIxiTEVJTRQmzuEbunxsYo2eaeC2inq8Fi60OKFEHUg50ISdfY27T1thuiQAk geIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ZrPH//KD"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si2348414pld.110.2019.03.29.09.31.36; Fri, 29 Mar 2019 09:31:52 -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=@google.com header.s=20161025 header.b="ZrPH//KD"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729748AbfC2Qaz (ORCPT + 99 others); Fri, 29 Mar 2019 12:30:55 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:43871 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728839AbfC2Qaz (ORCPT ); Fri, 29 Mar 2019 12:30:55 -0400 Received: by mail-pg1-f201.google.com with SMTP id u2so1968504pgi.10 for ; Fri, 29 Mar 2019 09:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=Lju3Sh2kmpmmLQeEIQ2kymRMSnNvrQCfL6/ZPFgSoEI=; b=ZrPH//KDXILltcSMKI4M4/hUUK8BM+cz1NNDwwL5YTOcX9sLI2MwKxP0L1r1qqyTE7 JkZjn96zwZd+Adxeg6pdlk+S5oTaeDbuMLALxDFIZJR48YBU6TIkq8vBOuMewAh/1bTt uZmaZjrIEM4jcCgPVRRcCqnx9Ul964ceAxo51ODx0pXHFA03vyjczjq/tfXXBFF6Y6eP tJP78qfBKpcmE+9zvb9EZamn5FQqKkU0dp55vLOpKl7rZDc+ei3Cvrg7/TzIZQEY7nPr QrnWJdxPHf/uvFf8e3VHwvTCXiLKPZzMI8I4762YebYp/ujqr1tp7MhhS6cm3uKIF69h 3E/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Lju3Sh2kmpmmLQeEIQ2kymRMSnNvrQCfL6/ZPFgSoEI=; b=DsTb2tVepkYmrAR9OD3x4n201pUQh0ofFHEW4QTODUIXdhhDZdNeCHOzBOL0JDwizm IoIxZAiW+YkCdjsWMB8dQSFkisSBQkta+oKlzAem2AXoVcrR5tE7uTy6wYgP7g3lQPF9 WtOMEDtBBvPYClGCNMc6i1I9eWu2pHnB6qoTxo19Q1i+ntA6tj5wo9ay4viJJ1p1zYJv p96l3JsGsTyEKkWNjvNrMweaLgqX9a8YA4Q85TAne+/iUuL/y8RsZ9g+/ZGea37LGg3V nhpEF6s2hDjQRgLa+CkFdALRe0qMVb5riYFDNrn9k6AkEwdyPF/mP5oTEflg0t6MTKgR HubA== X-Gm-Message-State: APjAAAXb/meXtwmaakokUEyEBCUH7aisCEMtTYVwfYiIiDEqgXV5KLnR 5GwTdUU4sw/5hb6PnmWEuJD1TfMFuw== X-Received: by 2002:a17:902:5c4:: with SMTP id f62mr140691plf.39.1553877054496; Fri, 29 Mar 2019 09:30:54 -0700 (PDT) Date: Fri, 29 Mar 2019 17:30:44 +0100 Message-Id: <20190329163047.223508-1-jannh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH v2 1/4] kernel.h: use parentheses around argument in u64_to_user_ptr() From: Jann Horn To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , jannh@google.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Qiaowei Ren 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 Use parentheses around uses of the argument in u64_to_user_ptr() to ensure that the cast doesn't apply to part of the argument. There are existing uses of the macro of the form `u64_to_user_ptr(A + B)`, which expands to `(void __user *)(uintptr_t)A + B` (the cast applies to the first operand of the addition, the addition is a pointer addition). This happens to still work as intended, the semantic difference doesn't cause a difference in behavior. But I want to use u64_to_user_ptr() with a ternary operator in the argument, like so: `u64_to_user_ptr(A ? B : C)`. This currently doesn't work as intended. Reviewed-by: Mukesh Ojha Signed-off-by: Jann Horn --- include/linux/kernel.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 34a5036debd3..2d14e21c16c0 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -47,8 +47,8 @@ #define u64_to_user_ptr(x) ( \ { \ - typecheck(u64, x); \ - (void __user *)(uintptr_t)x; \ + typecheck(u64, (x)); \ + (void __user *)(uintptr_t)(x); \ } \ ) -- 2.21.0.392.gf8f6787159e-goog