Received: by 2002:a19:ef0c:0:0:0:0:0 with SMTP id n12csp951582lfh; Tue, 1 Feb 2022 12:54:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAmHph3Boq57e1zh69gUZEI1MVQb9Bjb8Ig2C+3RqWjQVJcBxJPk9cWh4xHg9j6KQfJDor X-Received: by 2002:a17:90a:8c4:: with SMTP id 4mr4394884pjn.201.1643748883133; Tue, 01 Feb 2022 12:54:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748883; cv=none; d=google.com; s=arc-20160816; b=rBPZSE+p+DYs4Xuv2D6axvdl8OD/rB7CYrFOzVkTMZEp79/wjWfKqktSQo6EsbJ44+ 4xMg2dW+JmZOIPZzuQTdvhgmE0rnAW2Ybic2DfC+kBk2L+AK8QVcaAyxXDgqXse26a4i EvqzzcdhFh+W/VhVy+Mnlw02OfsB+jAmKQRy7SpbaLMzAcabd1ORCqXZiNQOfZK8zX4F /2mpeHkWskqNwlTcRIe3dtraASzBbbSmb6Ns6309kWYBU3Yu1QRV0mBN99lbMeFLAzYF Bj8fpY6TVgDvJ7Dw01KDYoqE8rNxH8VHx/F6EKkpF25bxHvpNc516rYSIpdAz6NYNROK tc8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=e3ZZiAySqbprwvaDG1hs3CTP647cwZT0Jm9kr093E2Q=; b=Varqz/jW98al2wVONGTEZvJtDX8kSykZqnCAmo6M4LebnE8pndfCHOMCLgW4IA3AUl 4tZx1GvvUok5MArr2wFJXOBJN0sF3orPjYfHjiFQ1N/TOHixLMKfcDsUNUmB7bMb1jVF 2DIa2tC6RvGE/MElLN5fY4n7tzApXV//3nwK0uyS8X3rP57/2iOieGHjVtVLCvfM3ccK 03aJQXsWn+TTXxmm97A1l40c9ukAJATc6KhRIVQ8KyLi2jO6JsGNNfKxoVRCvvg59kpo C7HPZ8LHXJw2yXLKldkeoYYnaSvte7fPHfRyBa122FanPgNzinW9zhRvPEKF+IIwUPrK qfKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SxiR2jAq; 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 lp15si4215397pjb.181.2022.02.01.12.54.31; Tue, 01 Feb 2022 12:54:43 -0800 (PST) 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=SxiR2jAq; 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 S230121AbiBAAIL (ORCPT + 99 others); Mon, 31 Jan 2022 19:08:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbiBAAIK (ORCPT ); Mon, 31 Jan 2022 19:08:10 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23A41C06173B for ; Mon, 31 Jan 2022 16:08:10 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id z5so13940117plg.8 for ; Mon, 31 Jan 2022 16:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e3ZZiAySqbprwvaDG1hs3CTP647cwZT0Jm9kr093E2Q=; b=SxiR2jAqx0RJdUj6gsKJ1LebXy+pOqEh08q6cYfYiO702h1SKnnV1x0ynw3JMlZecC JolizYnsCAPRLPwes8Bf7aXuxRI8Oz9bxryv1w5pzifcOfAbOy5YVqqeKNtXJVna3lL9 srnpX4jhy0Goq+9glObT1FL7WDSNCNQcVwzaI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e3ZZiAySqbprwvaDG1hs3CTP647cwZT0Jm9kr093E2Q=; b=EGimnKFLlz62MdjSsa+Mb9E0J45ob+jX2pydJ55zSgHKSFqfDhxY0MDLnPz0cJxxp/ EutsQ414Jn1Rv4bR/vXI7g+4GMRWrDGMTDh2IjuX+83gkY1TcaiOefXd4WY/uSaNMZUI X8i4R3MRmpcdTTObWe1kb0NJhdPI0rzIjZuUXnhZHOyUJA4IBVgRAVLCz6ghPr5SWy0v VTQJLltUD2fbTgsX7m2BIft2UTOoKaoK0vQdyh2O4wNIzShOFTJpxca5qh2yNe34AKdV YSI7ci5Tj5xA001utg7Mp8Y0vgsaePj+Yh4Ucmua94U07ykIJQUpADA2lnHM/8Iy+kKL uZdA== X-Gm-Message-State: AOAM531xjYfm/R72vUCrAc75+4yGJz52DdTFTQ3scxCcK3xGwwqlSHuH 0Az2Jj2pcYFbo6kko0Tkn9GrDLciOOfJbw== X-Received: by 2002:a17:90a:17a5:: with SMTP id q34mr37012466pja.1.1643674089650; Mon, 31 Jan 2022 16:08:09 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c8sm13008520pfv.57.2022.01.31.16.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 16:08:09 -0800 (PST) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Alexey Dobriyan , Shuah Khan , linux-kselftest@vger.kernel.org, Ariadne Conill , Michael Kerrisk , Matthew Wilcox , Christian Brauner , Rich Felker , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] selftests/exec: Avoid future NULL argv execve warning Date: Mon, 31 Jan 2022 16:08:07 -0800 Message-Id: <20220201000807.2453486-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1671; h=from:subject; bh=kZ/95lJt1ZckoQR1fzytjDeCsJ6t+JUzBzL4AXqKzBw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBh+HnnrFbzy50opMtbIN5Zhx1Vt1/4BuI9rimKtphI EOflI3KJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYfh55wAKCRCJcvTf3G3AJuNmD/ 4zEKZlGO0q21CWKrd8Pgq07v+XlK2pgyM5OURLUmezdnK6c52l5MOfne0FQzmVI82VAe3pbH9Xs3t+ onxh8VaeE98j6Piha+gWfzLdJbl9nfyEk31eFVmEc16LszHaZX17HTQOJp6YfGEZHKJ2TDf44yFm3h 91kFGjWCcukncS7qU1JGXMaAySbnBHIQoo0RU1yFybRmf7Py9K87qhnQpheBsNYSCnJxIytKdFq+4I 44DUOYLKG5GgCIr6pL5lRfgUVL61S4zyShmygXC7+1TIaCKbfJ4rFU3pBlildZzNCLgIh8Bbmu49Qz ZWZHwBR41kxe7yu28/UnISs/LFah8xlvgONHasmUfN5aXlhOhWxPmAaiyykEhskthNLTOcGnrBrquJ ID+KFH9vViv1dWu08C9L+vUhqicXSceHridIW1uaN9zw4eLE/3TJNiC5brlBzZD73TKLkbee3YGjSZ V1pzxgmT+k74qnautdNFJXCbZe3BK8U5+OAFD5xKKjLnz4MYCXIrLyS/x4xSp1LaPCkCTcyMGxmTVU BM5WCrB711+JxunG621R8KaVhugjS8yUA6XlZIB2yPbavj41Yo+n2rS5JbdkvwqHr48aLSS7f756bm MbQkSKWqGGGjIlt64oicdOWRocPvU+SlSkO36NXJcPgBfYhLAvOIas0uatFA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Build actual argv for launching recursion test to avoid future warning about using an empty argv in execve(). Cc: Eric Biederman Cc: Alexey Dobriyan Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Signed-off-by: Kees Cook --- tools/testing/selftests/exec/recursion-depth.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/exec/recursion-depth.c b/tools/testing/selftests/exec/recursion-depth.c index 2dbd5bc45b3e..35348db00c52 100644 --- a/tools/testing/selftests/exec/recursion-depth.c +++ b/tools/testing/selftests/exec/recursion-depth.c @@ -24,8 +24,14 @@ #include #include +#define FILENAME "/tmp/1" +#define HASHBANG "#!" FILENAME "\n" + int main(void) { + char * const argv[] = { FILENAME, NULL }; + int rv; + if (unshare(CLONE_NEWNS) == -1) { if (errno == ENOSYS || errno == EPERM) { fprintf(stderr, "error: unshare, errno %d\n", errno); @@ -44,21 +50,19 @@ int main(void) return 1; } -#define FILENAME "/tmp/1" int fd = creat(FILENAME, 0700); if (fd == -1) { fprintf(stderr, "error: creat, errno %d\n", errno); return 1; } -#define S "#!" FILENAME "\n" - if (write(fd, S, strlen(S)) != strlen(S)) { + if (write(fd, HASHBANG, strlen(HASHBANG)) != strlen(HASHBANG)) { fprintf(stderr, "error: write, errno %d\n", errno); return 1; } close(fd); - int rv = execve(FILENAME, NULL, NULL); + rv = execve(FILENAME, argv, NULL); if (rv == -1 && errno == ELOOP) { return 0; } -- 2.30.2