From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C085C43461 for ; Thu, 3 Sep 2020 21:48:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23A51206EF for ; Thu, 3 Sep 2020 21:48:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rFDGeZbJ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dNJhSL8+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23A51206EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V9KP4mYJyIVKeuBTbF5fA+XgOtRPE1a0Gw/YPof49QA=; b=rFDGeZbJhdMe+bQq1LlNI+T1b kk575AafWzMpVVH66I4Bd3S5drgINQiQymZLG0BXsmv6FFjexGa43Gl40eQ+4GJ37rcMO07BI7tmj ZnfqL2zQyY2BrcWRIbPwUzeFN4YqsbbbLQ2V/O5mTTlTj7qklnAVGZG7yWaEHTrDpgechSgK4hsJI BwJrZCyvS1WyGzFpYxd7q0sr6vVg/BQfWwQTmBkxN9b90HcrXYvo2d+gGG7gFKzJY5qsmMLI036+l 2aH2oNt9jei9gd8DJineHnjcMSMDfrXVkne+xCmk5tlhJxghDNw4/HjVV25UnM30o+yZL/BEDHrLv sct5lqlDQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDx4s-00031K-Bl; Thu, 03 Sep 2020 21:47:30 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDx4q-0002zy-FU for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 21:47:29 +0000 Received: by mail-pg1-x544.google.com with SMTP id 67so3154105pgd.12 for ; Thu, 03 Sep 2020 14:47:27 -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=sW3+i9jb9GQGw/rihL3rmHov3DBg+oJBsubVzV/94sk=; b=dNJhSL8+ekFbBcMLYdOiVh2ALsNUoTTm1VSxi4CeqOTnyYIMwnEHHJ7S/BtXgtuNOk 9HqSyGbwVU8WVdgO3Jvvq84XO+8XGzQl7x2oGWzDQCtlULUhdTtXclp3ZyOgcr4wIXRy ix3S72ob+JcdrTSNj6CS0A74L/1LVWKFX9qdU= 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=sW3+i9jb9GQGw/rihL3rmHov3DBg+oJBsubVzV/94sk=; b=Zt95yR7TXYTo7uRxNO5Se3+OpZrOhgR0EzHdz2nQ3ktJOG/GT99AzCGfQVHSU3UCX9 Vdb6fVpe8arA5MtU73YG2Rk4SprfuMTn7PWQtZNh05FN53Xe9JOjMdkwoNL7XIshqyIu vVDnhpcFdgt5mccqfVgeozmOn+Am2QY5uu3BOjV1Ik/tcsg+N37unrshgJPHz/qnYXpl OMOybEbEckc2WWa/87OiId12OWfV8bSr7EyJ6zNyqfGDTY91XQdfNDLYFJXrvUeJZq6Q 8idjWkux5jZz3lBIAj+/x/IQa1C26E/4fCzlAIxVoCHw8cZNprInXLeFQBP0+H5VgzCx mXEA== X-Gm-Message-State: AOAM530dcq49GIBUiPphjjILI3rdOGIIP7ADNlPYZtqPszKBc47QyyUl vx/xI95dHKNqE6N66oxbe2wRtA== X-Google-Smtp-Source: ABdhPJxA6AeZszGsabAFYmE7VAtam1/8zONcRaynFdaMlGHOxLgKqDQnRgIOet6kCjwYkvC+MGEMtQ== X-Received: by 2002:a63:e157:: with SMTP id h23mr4839131pgk.239.1599169646252; Thu, 03 Sep 2020 14:47:26 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e1sm3391485pjv.17.2020.09.03.14.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 14:47:25 -0700 (PDT) Date: Thu, 3 Sep 2020 14:47:24 -0700 From: Kees Cook To: Sami Tolvanen Subject: Re: [PATCH v2 03/28] lib/string.c: implement stpcpy Message-ID: <202009031446.3865FE82B@keescook> References: <20200624203200.78870-1-samitolvanen@google.com> <20200903203053.3411268-1-samitolvanen@google.com> <20200903203053.3411268-4-samitolvanen@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200903203053.3411268-4-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_174728_534457_C598BA1E X-CRM114-Status: GOOD ( 28.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, x86@kernel.org, "Paul E. McKenney" , kernel-hardening@lists.openwall.com, Peter Zijlstra , Greg Kroah-Hartman , Masahiro Yamada , linux-kbuild@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, Steven Rostedt , clang-built-linux@googlegroups.com, linux-pci@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 03, 2020 at 01:30:28PM -0700, Sami Tolvanen wrote: > From: Nick Desaulniers > > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format strings. `stpcpy` is just like `strcpy` except it > returns the pointer to the new tail of `dest`. This optimization was > introduced into clang-12. > > Implement this so that we don't observe linkage failures due to missing > symbol definitions for `stpcpy`. > > Similar to last year's fire drill with: > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp") > > The kernel is somewhere between a "freestanding" environment (no full libc) > and "hosted" environment (many symbols from libc exist with the same > type, function signature, and semantics). > > As H. Peter Anvin notes, there's not really a great way to inform the > compiler that you're targeting a freestanding environment but would like > to opt-in to some libcall optimizations (see pr/47280 below), rather than > opt-out. > > Arvind notes, -fno-builtin-* behaves slightly differently between GCC > and Clang, and Clang is missing many __builtin_* definitions, which I > consider a bug in Clang and am working on fixing. > > Masahiro summarizes the subtle distinction between compilers justly: > To prevent transformation from foo() into bar(), there are two ways in > Clang to do that; -fno-builtin-foo, and -fno-builtin-bar. There is > only one in GCC; -fno-buitin-foo. > > (Any difference in that behavior in Clang is likely a bug from a missing > __builtin_* definition.) > > Masahiro also notes: > We want to disable optimization from foo() to bar(), > but we may still benefit from the optimization from > foo() into something else. If GCC implements the same transform, we > would run into a problem because it is not -fno-builtin-bar, but > -fno-builtin-foo that disables that optimization. > > In this regard, -fno-builtin-foo would be more future-proof than > -fno-built-bar, but -fno-builtin-foo is still potentially overkill. We > may want to prevent calls from foo() being optimized into calls to > bar(), but we still may want other optimization on calls to foo(). > > It seems that compilers today don't quite provide the fine grain control > over which libcall optimizations pseudo-freestanding environments would > prefer. > > Finally, Kees notes that this interface is unsafe, so we should not > encourage its use. As such, I've removed the declaration from any > header, but it still needs to be exported to avoid linkage errors in > modules. > > Reported-by: Sami Tolvanen > Suggested-by: Andy Lavr > Suggested-by: Arvind Sankar > Suggested-by: Joe Perches > Suggested-by: Masahiro Yamada > Suggested-by: Rasmus Villemoes > Signed-off-by: Nick Desaulniers As you mentioned, this is in -next already (via -mm). I think I sent a tag for this before, but maybe akpm missed it, so for good measure: Reviewed-by: Kees Cook -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel