From patchwork Tue Mar 13 06:11:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10277797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E559601A0 for ; Tue, 13 Mar 2018 06:13:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10E8628B76 for ; Tue, 13 Mar 2018 06:13:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05AB728B9D; Tue, 13 Mar 2018 06:13:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E10128B76 for ; Tue, 13 Mar 2018 06:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750903AbeCMGMp (ORCPT ); Tue, 13 Mar 2018 02:12:45 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:44717 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751886AbeCMGL7 (ORCPT ); Tue, 13 Mar 2018 02:11:59 -0400 Received: by mail-pg0-f65.google.com with SMTP id l4so7557427pgp.11 for ; Mon, 12 Mar 2018 23:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9ALo/kIOw5kdn5Gm8UbMQSMSeUHvSy5lei3VU/i8+sI=; b=g/GfG9YTHitc4Y+heSYuHYG/CvsKdw6tk4LqubAvrkDG7WXvKC0J5tBHAJSqyxmojv zRp1e3T3fl2v9l+siuT6nNLL5hdqcAjFYJywf/mtQAyYGt9Mq16Z7Lae1vzs+PNKJD/y JwEiMkiqlCre+ev2akLvsbCLhAjRgJTzjBswA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9ALo/kIOw5kdn5Gm8UbMQSMSeUHvSy5lei3VU/i8+sI=; b=SS7SuhHVZf/xIXY7IFV4+XFJQyIPkhWkLzIt6gjY2of0Dv3Av4//zzgbKc6RbG3rSt pcWoMxKdAg8WRrDO+LHc+MU6daPBGHs+zaalW1C9VfyOf4+B10l/ddn5AMlNePKo1CW6 nCAuQNXqi+7sJ0DKQ0+CR4ZNwRwyeqvQ21XPb1I8D/ZAxZMp7KFdaIudUShYAiYBW8xR 4+okIIEPShrvrl5MgwVwcsKhl2ZHYnPZXvQ5xFRqK5eKf5r3Gsc5qjoABzFhGpruhYvG ARa/qxULkDWjGvsiGaF/se8X/A7ToP7/JPKtQ5PecJFJIsdWYGyVpctyzm/4pMSCcUPG ovDQ== X-Gm-Message-State: AElRT7EBN/kSoxUpwM2Q5lw0wWB0zZK7AKzychMyvCdsziA4Y0gp4C51 ZbIzT62Mnwr7EPQ9hHUhG38wkA== X-Google-Smtp-Source: AG47ELtlQKfc7aLm3tRvBGJOWznkeATMo7T8X8ReVXMWUYecxci44LaN9voyl3JwOJecKPCwXhaLmw== X-Received: by 10.101.96.212 with SMTP id r20mr8738654pgv.139.1520921518193; Mon, 12 Mar 2018 23:11:58 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:0:1000:1511:bde7:107f:fd5:44c8]) by smtp.gmail.com with ESMTPSA id c67sm20933553pfl.106.2018.03.12.23.11.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 23:11:57 -0700 (PDT) From: Douglas Anderson To: Masahiro Yamada Cc: malat@debian.org, dave.hansen@intel.com, yang.s@alibaba-inc.com, linux@roeck-us.net, Douglas Anderson , Matthias Kaehlcke , Cao jin , Arnd Bergmann , Mark Charlebois , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Marek , Ingo Molnar , Nick Desaulniers Subject: [PATCH v3 2/2] kbuild: Don't mess with the .cache.mk when root Date: Mon, 12 Mar 2018 23:11:09 -0700 Message-Id: <20180313061109.72629-3-dianders@chromium.org> X-Mailer: git-send-email 2.16.2.660.g709887971b-goog In-Reply-To: <20180313061109.72629-1-dianders@chromium.org> References: <20180313061109.72629-1-dianders@chromium.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As pointed out by Masahiro Yamada people often run "sudo make install" or "sudo make modules_install". In theory, that could cause a cache file (or the directory containing it) to be created by root. After doing this then subsequent invocations to make would yell with a whole bunch of warnings like: /bin/sh: ./.cache.mk: Permission denied These yells would be mostly harmless (we'd just go on running without the cache), but they're ugly. The above situation would be fairly unlikely because it should only happen if someone does "sudo make install" before doing a normal "make", which is an invalid thing to do. If you did a normal "make" before the "sudo make install" then all the cache files and directories should have already been created by a normal user and, even if the superuser needed to add to the existing files, we wouldn't end up with a permission problem. The above situation would also not have been catastrophic because presumably if the user was able to run "sudo make install" then they should also be able to run "sudo make clean" to clean things up. However, even though the problem described is relatively minor, it probably makes sense to add a heuristic to avoid creating cache files when we're running as root. This heuristic doesn't add a ton of overhead and it might save someone time tracking down strange "Permission denied" messages. We'll consider this heuristic good enough because the problem really shouldn't be that serious. Fixes: 3298b690b21c ("kbuild: Add a cache for generated variables") Suggested-by: Masahiro Yamada Signed-off-by: Douglas Anderson --- Changes in v3: - Use "uid 0" as the heuristic instead of install - Do the checking in the main Makefile instead of Kbuild.include Changes in v2: None Makefile | 6 ++++++ scripts/Kbuild.include | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Makefile b/Makefile index f1e61470640b..c4d2131831ba 100644 --- a/Makefile +++ b/Makefile @@ -268,6 +268,12 @@ __build_one_by_one: else +# Don't create Makefile caches if running as root since they can't be deleted +# easily; in the real world we might be root when doing "sudo make install" +ifeq ($(shell id -u),0) +export KBUILD_NOCACHE := 1 +endif + # We need some generic definitions (do not try to remake the file). scripts/Kbuild.include: ; include scripts/Kbuild.include diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 065324a8046f..581f93f20119 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -137,12 +137,14 @@ __sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$ define __run-and-store ifeq ($(origin $(1)),undefined) $$(eval $(1) := $$(shell $$(2))) +ifneq ($(KBUILD_NOCACHE),1) ifeq ($(create-cache-dir),1) $$(shell mkdir -p $(dir $(make-cache))) $$(eval create-cache-dir :=) endif $$(shell echo '$(1) := $$($(1))' >> $(make-cache)) endif +endif endef __shell-cached = $(eval $(call __run-and-store,$(1)))$($(1)) shell-cached = $(call __shell-cached,__cached_$(call __sanitize-opt,$(1)),$(1))