Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp64347pxj; Wed, 23 Jun 2021 15:48:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzo+mUG+5H++0Q8QoOTA9GdL8zuQVk0BeczJ3FuwMmIWU5YwNCqDgxQ+NaXJ79aCgeBaLxC X-Received: by 2002:a5d:9750:: with SMTP id c16mr1527208ioo.142.1624488506306; Wed, 23 Jun 2021 15:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624488506; cv=none; d=google.com; s=arc-20160816; b=EBkyL2aLm4gNi0C3XfWoXOwnTVbs8eqW7MRHI6MNtq9SltVTLH44qVQnzrdYtAklVF 46sZMrgzbTAGjGcj25QK8tdDmER10c+22nKKYn58vpKr7/momweb7AX1ZHxPYegy6R1F Q9+Jv+Eap3LoSe8LxF1ENpIF/fuYctkN8AbICiTeZvWBzAyE9xipuZ4HydByMYlJgW48 B8k63xr7+X1vHcU4KYCxKB7R4vKnHomZIxgxJy6Pr0VBRS6nvIvhPaStbxWwkK7IfAaE CelU6LUcEH06p0nq/QPByXWS2csL+N3bcVdTz6eNWTJRwEAfGScyt4BttxBW5K/8EpPi i4hw== 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=8fAh4y0OB0EQHzmH30AhixLLr6acGSavXwUpuUJpLnM=; b=08KZJlNy8VXY7bRw4e3adDL/B0ouew0Mkn5jXHAxKbFHkIyAJ8F+xhB2rYFN9O5Ym7 stLKugJcL1dRjLW4NC4xa2o+ZLxZDy0K36uidcP0G++x+ueiUY1N5BEwzQFghTMEU436 obrY4Xs67+nCKioUiFGfm2Kd8WYq2cRpuMjPZHriceyno2q8rrK4V36kkSQVb84zglhn t6cm2HZSGjQoWMRRigTb8A4/gvQVOt0rFbpvdpwG0Vl06gy3nXWiNnIdxUHprOgfuW0B P+PsEWfc3xWfYVWlK2tpe21bc8UeT9llwYa/x0gvlCDFj2iJ/PWDvb62hK6T0Zd/Iytn fd8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iQSYf2Ji; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si1081140ilr.53.2021.06.23.15.47.39; Wed, 23 Jun 2021 15:48:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iQSYf2Ji; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229864AbhFWWtH (ORCPT + 99 others); Wed, 23 Jun 2021 18:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbhFWWtH (ORCPT ); Wed, 23 Jun 2021 18:49:07 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A66C061756 for ; Wed, 23 Jun 2021 15:46:48 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id y13so1922377plc.8 for ; Wed, 23 Jun 2021 15:46:48 -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=8fAh4y0OB0EQHzmH30AhixLLr6acGSavXwUpuUJpLnM=; b=iQSYf2Ji1gQzTW1DUhkt++SYi4wMGXiE/j2gPcKWSSCpt60rrrH8tpnKOQ0TMUyNYd bF/8h2JGWRl78uOUwAU/3HQa3U7BSwTxH9J8b6g4Fo3m2YDBcw5UebKn+MuvQnpitYET +UtODHFed+1v20RqHIbAOeKryMpu1wbaCfqOw= 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=8fAh4y0OB0EQHzmH30AhixLLr6acGSavXwUpuUJpLnM=; b=ryZ+i+X6Tvac4kc63SZgMpnWxS+Z17sJngpuKqdIVxpCAjp5IvZnetyN2QWFUk+Aul RtURNRxjg2x8/AIUUsAnQTlOQN+oQ8fXTUXztsXGVjdgUGPQZGyx59iDTdW/CMRp+xxM e3RDsNp2INjum7nusOrUcRL7/YE0iMeGqhRUhEQMfYrEn18E6J8CuJ4c2Wp7iDeRsFNS 0SYgfcruzGspUyB1eID2eg5BM9cdmcIqWQ+oB/2oKTmEzwe1KEAS+KC/e0xyAF0Soy13 A6aWXSnFh3+/md7clsqT7avNQITohlvZeUjsOgLtxcjtPZvnv8J1Bn5zbptPkz+onJRs bcKQ== X-Gm-Message-State: AOAM53314ikbDIwS3ax5cVAn+kcIuLN8rLszTYt8TC61Ih5Rj7+z1Y61 IZyvbjdGuAP3B3Dcw2c8e+Io9A== X-Received: by 2002:a17:902:fe0a:b029:11d:81c9:3adf with SMTP id g10-20020a170902fe0ab029011d81c93adfmr1559888plj.0.1624488408037; Wed, 23 Jun 2021 15:46:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u9sm130456pgp.90.2021.06.23.15.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 15:46:47 -0700 (PDT) Date: Wed, 23 Jun 2021 15:46:46 -0700 From: Kees Cook To: David Laight Cc: 'Guillaume Tucker' , Shuah Khan , "stable@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] selftests/lkdtm: Use /bin/sh not $SHELL Message-ID: <202106231231.9B858B95A@keescook> References: <20210619025834.2505201-1-keescook@chromium.org> <42f26361db6f481e980ac349bf0079ef@AcuMS.aculab.com> <202106230917.FE2F587@keescook> <76a575d1364a47458d27c76c65b673b6@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <76a575d1364a47458d27c76c65b673b6@AcuMS.aculab.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 23, 2021 at 04:27:47PM +0000, David Laight wrote: > From: Kees Cook > > Sent: 23 June 2021 17:19 > > > > On Wed, Jun 23, 2021 at 01:43:04PM +0000, David Laight wrote: > > > From: Guillaume Tucker > > > > Sent: 23 June 2021 13:40 > > > ... > > > > > diff --git a/tools/testing/selftests/lkdtm/run.sh b/tools/testing/selftests/lkdtm/run.sh > > > > > index bb7a1775307b..0f9f22ac004b 100755 > > > > > --- a/tools/testing/selftests/lkdtm/run.sh > > > > > +++ b/tools/testing/selftests/lkdtm/run.sh > > > > > @@ -78,8 +78,9 @@ dmesg > "$DMESG" > > > > > > > > > > # Most shells yell about signals and we're expecting the "cat" process > > > > > # to usually be killed by the kernel. So we have to run it in a sub-shell > > > > > -# and silence errors. > > > > > -($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true > > > > > +# to avoid terminating this script. Leave stderr alone, just in case > > > > > +# something _else_ happens. > > > > > +(/bin/sh -c '(echo '"$test"') | cat >'"$TRIGGER") || true > > > > > > I was having trouble parsing that command - and I'm good > > > at shell scripts. > > > I think the extra subshell the 'echo' is in doesn't help. > > > In fact, is either subshell needed? > > > Surely: > > > /bin/sh -c "echo '$test' | cat >$trigger" || true > > > will work just as well? > > > > Ah yeah, and I just tested it to double check, it can be even simpler: > > > > echo "$test" | /bin/sh -c "cat >$TRIGGER" || true > > You can probably even do: > > echo "$test" | /bin/sh -c cat >$TRIGGER || true > > (moving the redirect to the outer shell). Actually, it looks like the "write" is already happening in the exec'd process, so this can just be: echo "$test" | cat >$TRIGGER || true But it still can't be: echo "$test" >$TRIGGER which is what I had over-engineered a solution to. :) -- Kees Cook