Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5805268pxb; Wed, 26 Jan 2022 23:03:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyN8m3VYmUIzZ5QcLlrDM2fBZ2tNZFtzsv4cbBceyxz4wxMGOv6PkAfAFP37p7ezUkGvYBN X-Received: by 2002:a05:6a00:244b:: with SMTP id d11mr1696442pfj.49.1643267008841; Wed, 26 Jan 2022 23:03:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643267008; cv=none; d=google.com; s=arc-20160816; b=vIoQpraXMA5FBOtN/qrBfy+EskoTRJjdUcJOP3Qnj1S2OCDi0O1CIrm0P96Lxm3tA/ f4YgdlRUr7/Kh7dYRpQtKGWZ/bzVM8ZgFN645+x2S1i4PWU+ivKZjKQVHlWeqi/YrkYs w8BDdxrr4SeZ/X7kzuGC0U0MLSF/YuiKiyL4D7OzL7C3xVDv7HeL5N/Bpn1yohkFsU6V LSPTOn0KSLRfuUhy/sY8ZcjzlvfVb+cBIep6/+uf3SimYITFOlvIs+aq3CUtQcDZQojP U1qOR10BsJpQoPWb3AjUdtFtO0RIIER7KHZ3e8DoJeYaeEd1gAF1oCoHCC/JuB3FyTOG xUGw== 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=DwrekoWwD7S8yj0PWXXec9UCQ3/KKV/tBb2QonKO67w=; b=o8KZj7AwxPMF3m325q129CE4ob7YMK3UvZGjYMpm/J5sN+cC9DQQuf6Bt95YJqj+U8 v21bwcEVH+ewgyhjKv54wfJBCQ8yCBq1PNhrpAJqZwsauwgkqWHEAfawxc3B8wq8oID0 7/a4PFsnmkAiTxHhYK8mk9LrynM6ZTmadtl8BalLiU676SNj+tX2UpSyoQqqlgXBOzXK rsaLpXBmJerfotccl/C/NQ7NToDgcyNM1J6KzRfBpWo9UTk7GzgUSrvjbHpBOBVlPD9p b1fbIdstp6lnbAV9qL26M5ojWWACyuWRI+Tq/w2cyz+blQpmuXEHipiD/h0YNRfvnUCg wqJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=B7sSz9g5; 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 2si4800080pja.40.2022.01.26.23.03.16; Wed, 26 Jan 2022 23:03:28 -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=B7sSz9g5; 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 S232814AbiA0AAD (ORCPT + 99 others); Wed, 26 Jan 2022 19:00:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiA0AAC (ORCPT ); Wed, 26 Jan 2022 19:00:02 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96B76C06173B for ; Wed, 26 Jan 2022 16:00:02 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id u11so978739plh.13 for ; Wed, 26 Jan 2022 16:00:02 -0800 (PST) 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=DwrekoWwD7S8yj0PWXXec9UCQ3/KKV/tBb2QonKO67w=; b=B7sSz9g57GHF8TphX5iKf/ReceRtURdiZA257rxyFhPEJ2GeUmj34TjbX8UnzDaFUs Dn0/XCD9N5x9fawmkAjfCNtft7zD8ix2w2zLHJ6jpbeC07CPW2SGrexilsMvkZwju4hc IuISRG/sx1OpZo7RhodjbGyfx+DdIdhX/G9IU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DwrekoWwD7S8yj0PWXXec9UCQ3/KKV/tBb2QonKO67w=; b=E24tyNaOB+02F0c5vqPP0WAGUAkIkZWr6gDXrHQtYR83aN7WtJ3/Q547AHPb/+f1i9 HpHkvwqXo5ZnVWPUiIBGyIdPfdUMvNg+4ytwmZxKr49/SSxEdNo1KE2ut+tQL6PuEORB hKfQh4TTGNsUinBhHTAtxMtoig3+Mk8MqO6RgeWp9LneAMc/2KbMZ5KMUKQcGLTfH1r0 +CMOtn//u4k41cTHGrNWe3uReDi2cxgaRu+JXEUAHOPfBwu8l+cNrMTd5mifKg2DPiWZ WHC4rV6aD6MkDxglpZwFHNDfly94y87s9bIVkBgkxzA5gK42qNQws7KtCKzM1frYC/o7 mThw== X-Gm-Message-State: AOAM530hb5jhqfhBaX33ROFIGF/Qv2mxevtRZ6XkeJeuYxxKWOo7bI21 8usDhJtJDAYH3luFjX/BQyR4lA== X-Received: by 2002:a17:902:c409:: with SMTP id k9mr1083833plk.132.1643241601975; Wed, 26 Jan 2022 16:00:01 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q17sm3265766pfk.108.2022.01.26.16.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 16:00:01 -0800 (PST) Date: Wed, 26 Jan 2022 16:00:01 -0800 From: Kees Cook To: Alexey Dobriyan Cc: ariadne@dereferenced.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, ebiederm@xmission.com, viro@zeniv.linux.org.uk Subject: Re: [PATCH] fs/exec: require argv[0] presence in do_execveat_common() Message-ID: <202201261558.DAA974162@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 26, 2022 at 06:02:25PM +0300, Alexey Dobriyan wrote: > > execve("...", NULL, NULL); > > I personally wrote a program which relies on execve(NULL) to succeed. > It wasn't an exploit, it was test program against IMA-like kernel > "only whitelisted executables can run" feature. > > Test copies and "corrupts" itself by appending \0 to the end, then tries > to reexec itself with execve("/proc/self/exe", NULL, NULL); > main() if run with argc==0 exits with specific error code. > > Appending \0 breaks checksum so working kernel protection scheme must > not allow it, therefore if execve(NULL) succeeded, than the parent > process doing test hard fails. > > Also appending \0 doesn't break ELF structure. In other words, > if executable A is working (and it is working because it is running) > then A||\0 is valid executable as well and will run too. > > This is independent from filesystem layout, libc, kernel, dynamic > libraries, compile options and what not. > > Now QNX doesn't allow execve(NULL) and I don't remember if I changed it > to the next simplest variant and I don't work anymore at that company, > so I can't check :^) > > execve("/proc/self/exe", (char*[]){"Alexey", NULL}, NULL); One of the various suggestions was to inject { path, NULL } when argc=0. Given that execve(path, NULL, ...) is being used at least a little, hopefully there is nothing that depends on argc==0... :P -- Kees Cook