From patchwork Fri Nov 2 15:56:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 150064 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2243811ljp; Fri, 2 Nov 2018 08:57:26 -0700 (PDT) X-Google-Smtp-Source: AJdET5esA2LqBgpmw5EneNMfIJRafVAGPnm/RD63DMeH7U52Wct3L33nOlr23vAeWFJpJAId/kp1 X-Received: by 2002:a62:5881:: with SMTP id m123-v6mr12404613pfb.160.1541174245955; Fri, 02 Nov 2018 08:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541174245; cv=none; d=google.com; s=arc-20160816; b=YI/ThK08XFJk1ps+BKoQMYXT77YF3QEB7H8V5mj4kahLtFxpPhUmu8Tb9H/vN+J6rE x6eWBe5qkLVzlLMvlIEfLzNsJj0KYGiPkbQDUkoCzy1eEmjBq55Mxqgxspi3dFwXrcDQ 4Uf94QOV6getiDIy8SsJFnvlZOAoyEOS+7L/nBD+kMknAg/jMaa677OzNFyglRr06evE MTbz4jVVVjFBxHmiuM/ViOt5RUf2kh2oJfC3g+bkJMKLw7W8AnKmPSKxpkAQTZ3qT2lk b1BC/C6r00I6nWjj1YwA35785IGZo9dsr/Qkzg19b3TTV9pk6mU6eTcJ8SSY+8ExXkEj IdDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=qCg0CofdTSvjsGOtUrcR1arYYNcYbD48wIH6JmAspP8=; b=MSVzvBxchIW/2fZ39sFQvS0PwFKBMz4Dtz9UaVU+gnAAQwF+4VAen6kvM2E90VNk+D kEuAKvYufmsYyKi8dwPRvvrdZFe4ZpYQC2kWVjxGxfInceg67NyUwLhZDs3ZwDbCSX4q 674or1RVRPRHJtZJurV7q7RKmEp0sYLezCwyTfY8v8Y6sA+/FPsyZ/IzlLvQRs42KzY/ s1wC6xsAbULeZMoAYN+OiJGhb5YQw58QtGK8GcgQ3Ja3MpRuIsZIFjz1fMej5yMDhjA1 xw+BR6oyzr7MZQGxkkpd0T2PTVSGgy6KMX+cp4AkqveYHC9OAWyDRc0lTn+dvshl8JKY +2Iw== 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 i66-v6si35160498pfc.173.2018.11.02.08.57.25; Fri, 02 Nov 2018 08:57:25 -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 S1727989AbeKCBE4 (ORCPT + 32 others); Fri, 2 Nov 2018 21:04:56 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:46769 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbeKCBE4 (ORCPT ); Fri, 2 Nov 2018 21:04:56 -0400 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1MEFCF-1gQYJg1s9d-00AD8f; Fri, 02 Nov 2018 16:57:13 +0100 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1MEFCF-1gQYJg1s9d-00AD8f; Fri, 02 Nov 2018 16:57:13 +0100 From: Arnd Bergmann To: Andrew Morton Cc: Masahiro Yamada , Al Viro , Arnd Bergmann , Changbin Du , Marc Zyngier , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Dave Martin , Kees Cook , "Levin, Alexander (Sasha Levin)" , linux-kernel@vger.kernel.org Subject: [PATCH] copy_{to, from}_user(): fix compile-time sanity checks with gcc -Og Date: Fri, 2 Nov 2018 16:56:58 +0100 Message-Id: <20181102155710.2299475-1-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 X-Provags-ID: V03:K1:X+qVvBb/GzVwHU4DkPImdxvpq9fq/2URLIt0PbJ2CcEgtbtM1Pw mV8YFLzx95+HCpvZ2xZTrbo8c9Uj0QCancrFnk1SwmDVootXzosRAWyIOOdTG9OCu9ffdp+ epWOLpUuN6IidNTa4RMB4/7F/4ausEYhsZ48Sbe8K5/tZGDI6fioty7GoOjBtqEpkGnnTXV wRL1Ge0MbDBIXRDuGqm4g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V01:K0:exWrVnSCmUE=:owrhYdF4wLavopmMG2oplp fRiupg9zSBp825elD5AYIIKJkEXN5mBju4BqcwEUTdr3VZ/+xX9697i+m/ydCFJZoK2oCaPue rXMqQxz/ZCKCcy3bDv2E+GwVrHGKKbfer0o5RayGttd76ecwraLhf6lczF/JLvhSZWLq99EVB 0kMarh5EKFUOG61zclvXbXPp+Of542lO9F1Nyu3J0LHqDQjoIQZD4zmqak6ft7j7ucEZpUcja WzA9W+Rj871w0FTTozedmE5ZpNxT/3K85pamfcvRWRheKQzfTlv+f0QvZG7eg3hlSvOVXT1rM uTwGmtmY1IyYWyZQQwn3DX0GPim5vXWzJKSIuiLsQI9UskP617UvQ6lfoD338AYjRhJRc2qOT 37Giwn7DTPwQ+rKVt3WfOZ2zRz6iKuxvMdnXkv/KFIC0sm1ImU3dlRl8Ofn00HuKKEbd0+x+i kVx4fvwqTO7kN5hYiHUHeXdA1bw74doNACyT/LSCHO5kz927A6jtLz9pDooDfIMBpGrGjGgF3 EeA+iOnsgsitXVh8MZJIxOHut/liMPkcA1F1LNAMqIDEdZUsbpEz6BPo0VlNLgi4WhkA7JYSb mRGx9cGfiBT1LbdPIuTPu8NPQ6vrSsTriGmKEqF0mv3/z87L7h4FC9wMHCvGwV0R2WSVuvxhk kDLHLYLs54qGB5+a9HnBbrJQb1xBz7GRJHj5MTZudzNLu/ZijV9HhbVD2b4TaO4q5m8Y= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When CONFIG_CC_OPTIMIZE_FOR_DEBUGGING is set, we get countless warnings like In function 'check_copy_size', inlined from 'copy_from_user' at include/linux/uaccess.h:146:6, inlined from '__copy_siginfo_from_user' at kernel/signal.c:3032:6: include/linux/thread_info.h:147:4: error: call to '__bad_copy_to' declared with attribute error: copy destination size is too small It seems that constant propagation doesn't work well enough to make this code reliable, so turn it off for that configuration. Cc: Changbin Du Cc: Al Viro Signed-off-by: Arnd Bergmann --- include/linux/thread_info.h | 5 +++++ 1 file changed, 5 insertions(+) -- 2.18.0 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 8d8821b3689a..762f379bdf5d 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -138,6 +138,11 @@ static __always_inline bool check_copy_size(const void *addr, size_t bytes, bool is_source) { int sz = __compiletime_object_size(addr); + + /* constant propagation doesn't work well with -Og */ + if (IS_ENABLED(CONFIG_CC_OPTIMIZE_FOR_DEBUGGING)) + return true; + if (unlikely(sz >= 0 && sz < bytes)) { if (!__builtin_constant_p(bytes)) copy_overflow(sz, bytes);