Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1239625rwb; Wed, 16 Nov 2022 14:25:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5zeXDl3Dd3/L4WExF42YLN9T+HrwiEuIXONFCVqdVAVRJiFdK8MkxMOxsCRkryX4r8VfU5 X-Received: by 2002:a05:6402:949:b0:464:3f28:3707 with SMTP id h9-20020a056402094900b004643f283707mr20826315edz.411.1668637514848; Wed, 16 Nov 2022 14:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668637514; cv=none; d=google.com; s=arc-20160816; b=uASIDgSIODKWuiidBJi1ves1+68kqVWCWSO8F/Q1UYsD0ItCf56ZjfKya7S9fgQ3js bRzlHS+rj+7617hHWfi5HQKTPAmh9DnDL4Tz4DVmJna0w0LKBmEzkm82LPGGCq9S2AXM U2YqPQ35s/FlVhEywjc4wvRfXOHohcWoBZ9978ghH4EP2PrOBgW4puVBHDzy/blaf9ir Ap2UyXhJu8LHCG91yLK91J0Yq8jb15UxTdafuPeT1rYM8nKOrUXGq8kUFz4TQzcfNCz9 kqx3948j0lidP4q0ND1FTCf4K56NxMY/2LaJwbjMNEtSTnfE59EN++/hNv+IC+7w4m2T JViw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=USUBJEQYr7zCoXTygKbEoAl5/bOlE5sjNcmPMMnNO+I=; b=F+ra8qQE0qm+yEy7sBE5P4FmjKC9YgPifkxn9kB1eScRkHU/38h+bTuv0qbYIUTA6j KSp7ljXff5yZARHgCfuT6s3UWLJfSrlgpB7ckGZ09aAxDPLXEIoqqeynQSUm4TGMNADp WWvrbipTAPQWaGCienZbtXH/JmXSnVhojtvIM2IjjaVsZpCdaNXjqtRzb+1O5HQCTEOw kWgyS9TPQoOzlqZM551C5VaCDYnOvao6o7muydReKYXs69AVcKxkTNMob41d7eNYTVgI xBLgxLpRqa2Tt9CmDpSex0pBeESxxM7blRg9+3NDCh2vToV/09aJVo55Uid54I3yImQB uySA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aOXRrMzL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020a17090603c600b00781dbeebeb1si11398020eja.585.2022.11.16.14.24.53; Wed, 16 Nov 2022 14:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aOXRrMzL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234020AbiKPWH6 (ORCPT + 90 others); Wed, 16 Nov 2022 17:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233725AbiKPWHw (ORCPT ); Wed, 16 Nov 2022 17:07:52 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B0A65E49 for ; Wed, 16 Nov 2022 14:07:51 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id o13so188638pgu.7 for ; Wed, 16 Nov 2022 14:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=USUBJEQYr7zCoXTygKbEoAl5/bOlE5sjNcmPMMnNO+I=; b=aOXRrMzLYEFxRa8SaRW4Ih90tXTtmdiLlMY5L9fwgvk5ZkEvOJPwSUwRFH0VVe0KNX Tf7RQspv3rT5ZdHZwrc2/gApQJqkPiCcet8AWh1asaTK6+tRSU0QJ9WlaBD3CZ1nrUfF RLbgixYHaOds9zuQVBWGzWco4eawNq4P2jfKY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=USUBJEQYr7zCoXTygKbEoAl5/bOlE5sjNcmPMMnNO+I=; b=oycMwmIHfA++8/R4cp+kyDDHcJr9gz4KLy0G8QTAQZHdDP/yR61ftSaMjOrCD/UumU tIetm3w80pgapnwr5ErSk4HW3eELy4v/AkEnUpI41oyTt7zbHiRTd68tphmPncm9Svr4 PAb/vh7oydA58pFZoRqKfVWGnx4oNv4LwzPn/RN/yiE9on+x9ChkbkmaSDqvJ5Z8y2OY 6qL8O0zDGrg44bvqpUagUKD4kT7xRpzGr8VmfQirQCKZR+7DRG0pK5/ZdAMjoOi69REr 7dlBNc0pqXGG4urT56piqluFLITeT9JqIj1d37VwDNfoyehh4t8k0xbqDwsXkWit1ABS eXhQ== X-Gm-Message-State: ANoB5pmRezQVxrfcum/4ai/YK3AcZSXFWccoQQhhrBBL0+sJbIeB8uMc dDh8XzNc22EM8bLbTOxp1n/3fw== X-Received: by 2002:a63:535e:0:b0:43c:7da:e64b with SMTP id t30-20020a63535e000000b0043c07dae64bmr22822743pgl.231.1668636470644; Wed, 16 Nov 2022 14:07:50 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id u11-20020a17090a450b00b001fd76f7a0d1sm2093989pjg.54.2022.11.16.14.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 14:07:50 -0800 (PST) Date: Wed, 16 Nov 2022 14:07:49 -0800 From: Kees Cook To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Jiri Slaby , Nathan Chancellor , Nick Desaulniers , Michal Marek , Nicolas Schier , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v2] kbuild: fix SIGPIPE error message for AR=gcc-ar and AR=llvm-ar Message-ID: <202211161406.EF075E28E9@keescook> References: <20221027162839.410720-1-masahiroy@kernel.org> <202211161056.1B9611A@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 17, 2022 at 05:37:31AM +0900, Masahiro Yamada wrote: > On Thu, Nov 17, 2022 at 4:01 AM Kees Cook wrote: > > > > On Fri, Oct 28, 2022 at 01:28:39AM +0900, Masahiro Yamada wrote: > > > Jiri Slaby reported that building the kernel with AR=gcc-ar shows: > > > /usr/bin/ar terminated with signal 13 [Broken pipe] > > > > > > Nathan Chancellor reported the latest AR=llvm-ar shows > > > error: write on a pipe with no reader > > > > > > The latter occurs since LLVM commit 51b557adc131 ("Add an error message > > > to the default SIGPIPE handler"). > > > > > > The resulting vmlinux is correct, but it is better to silence it. > > > > > > 'head -n1' exits after reading the first line, so the pipe is closed. > > > > > > Use 'sed -n 1p' to eat the stream till the end. > > > > I think this is wrong because it needlessly consumes CPU time. SIGPIPE > > is _needed_ to stop a process after we found what we needed, but it's up > > to the caller (the shell here) to determine what to do about it. > > > > Similarly, that LLVM commit is wrong -- tools should _not_ catch their > > own SIGPIPEs. They should be caught by their callers. > > > > For example, see: > > > > $ seq 10000 | head -n1 > > 1 > > > > ^^^ no warnings from the shell (caller of "seq") > > And you can see it _is_ being killed by SIGPIPE: > > > > $ strace seq 1000 | head -n1 > > ... > > write(1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14"..., 8192) = 8192 > > 1 > > write(1, "\n1861\n1862\n1863\n1864\n1865\n1866\n1"..., 4096) = -1 EPIPE (Broken pipe) > > --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=3503448, si_uid=1000} --- > > +++ killed by SIGPIPE +++ > > > > If we use "sed -n 1p" seq will continue to run, consuming needless time > > and CPU resources. > > > > So, I strongly think this is the wrong solution. SIGPIPE should be > > ignored for ar, and LLVM should _not_ catch its own SIGPIPE. > > > > -Kees > > > I thought of this - it is just wasting CPU time, > but I did not come up with a better idea on the kbuild side. > > I do not want to use 2>/dev/null because it may hide > non-SIGPIPE (i.e. real) errors. Yes, I've opened an upstream LLVM bug for this: https://github.com/llvm/llvm-project/issues/59037 -- Kees Cook