Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp861522ybm; Fri, 29 May 2020 14:08:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAj6EtBegGbCmjncLsssJp1PnHPrn1i+Y6LhYWCY16FqMQlwYKU9Ubdtpl3A4wwKQSzBbm X-Received: by 2002:a17:906:fcb9:: with SMTP id qw25mr9834893ejb.326.1590786536840; Fri, 29 May 2020 14:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590786536; cv=none; d=google.com; s=arc-20160816; b=C9Tw5cik6XaisFLfGo3xdVHFnw4JRFbEJoJj/I4XutghkhwuBp5s+Q3ojHjMBWYVtd 8OFuSkb5DMxvbtLnCb2TWgkwhFnZJc1xv4gPdpUZVR02GewDWNtOxpSCWzJrLwsyxrDF tjwFB6YAR3Ss98+MxYXgJifh9kOzJvOSwiqf9NjQoJp95iaeeGF0GXUk6GzJZrwusjKV iLaRX85v6eLFc57JFUBIE0oOpzl585ArtiqdjA34wKaTXFjjCvLid0JBHidS6C5FSV2c Y5XULLU0u6q81rpWd13Lk1EYZPwlE4RcY7Ftpw5a3D75fqHU+JvSqSnPojVaZYoC9P2c aRPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=p/Ov8sL4DrAiZu38/tMtDPHCSaLR76xmY23DLMflZaw=; b=ZMDlfA3TPf3G/lqp8vZpjWKF2Aqrp6ZQupseqqqrK8+KVcjFIz2kGumJa+XOZP782O yzrDVj2C8fmhydod2vZf2H2DhS2Ns6pfdKLMfCl/P/+Hkk2t9AW7O0Me89gzOHO0sMYp +AV0ZbVsRBg3dT2wjxUCDYvYxYvJF5yC1Nc8wynKxuQTbTyhD6eVeoSJEvzpznSMcIfd 4uRstPMezeBL+nKV9FSIxl/uE/TbhysSngUfaF+YSYIskDUG89fclE4eWgxle/eZOcX3 GvMCQxuXfz+5YUHPxTHwcneR01rneOPlffpElygAfJUz0J1LAcQz/kD7cmi5bMLZjIA8 5d6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M2zfIhsK; 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 k13si6705197edn.344.2020.05.29.14.08.33; Fri, 29 May 2020 14:08:56 -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=M2zfIhsK; 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 S1728304AbgE2VGi (ORCPT + 99 others); Fri, 29 May 2020 17:06:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728154AbgE2VGh (ORCPT ); Fri, 29 May 2020 17:06:37 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A01B4C08C5C9 for ; Fri, 29 May 2020 14:06:36 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id n15so446654pfd.0 for ; Fri, 29 May 2020 14:06:36 -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=p/Ov8sL4DrAiZu38/tMtDPHCSaLR76xmY23DLMflZaw=; b=M2zfIhsKul4HQv2VnAJO+u/iqfebyos6KWaRuwPJ56zlnFgHqQ29FsB3gZUCGMif/b Keic6ZWRzMUhkiTfftlD4aXXP6WYNcSt183Lo0Wc3aGOSjxFtY9gkQJiAa9abPA7dC5D i6Oi9BA/aAlbsvlXin3WuiduzcXkmaaq/8D8c= 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=p/Ov8sL4DrAiZu38/tMtDPHCSaLR76xmY23DLMflZaw=; b=dHEzPUTJ6E7jJiTZzMyZWVTQdKzscrp1hS4PvhALCXkjIPnqlJzQC9ZojYkJ7QJ0CP XVSQOqlOSw6w0jffahHXwPMzypE+RvZ2jza3422yJRCcZeVQBORufXlLbFr4xDPQrVuQ S92rPDjcKZ5x2oIXt3XIsDLbIlWYUGi2S+LXFODlR/lgB9zWG135w5o7zLg8oh8SDEXt 9Op6O+IMTIHc0Qjy5+V5EisNq5maB9g1TVZt+07iZGEMmJMrHovnE8sF1HmDJMK/SRYC Jhxs6usZrb+cz9Jr0qPpgCFB5sLJ+zT0wqTO062/7ZWw6C5ECnBucPJ3GxhcGUsMkniv f36A== X-Gm-Message-State: AOAM530gqPRtHE9539ISx9zlucKDkHIG0DFX9GP2lCal791AqSVMskUR LBstfXI1seUp88Yd1H/NbcAeaQ== X-Received: by 2002:a62:8487:: with SMTP id k129mr7726912pfd.296.1590786396090; Fri, 29 May 2020 14:06:36 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q3sm8067695pfg.22.2020.05.29.14.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 14:06:35 -0700 (PDT) Date: Fri, 29 May 2020 14:06:33 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Oleg Nesterov , Jann Horn , Greg Ungerer , Rob Landley , Bernd Edlinger , linux-fsdevel@vger.kernel.org, Al Viro , Alexey Dobriyan , Andrew Morton , Casey Schaufler , linux-security-module@vger.kernel.org, James Morris , "Serge E. Hallyn" , Andy Lutomirski Subject: Re: [PATCH 1/2] exec: Add a per bprm->file version of per_clear Message-ID: <202005291403.BCDBFA7D1@keescook> References: <87h7wujhmz.fsf@x220.int.ebiederm.org> <87sgga6ze4.fsf@x220.int.ebiederm.org> <87v9l4zyla.fsf_-_@x220.int.ebiederm.org> <877dx822er.fsf_-_@x220.int.ebiederm.org> <87k10wysqz.fsf_-_@x220.int.ebiederm.org> <87d06mr8ps.fsf_-_@x220.int.ebiederm.org> <877dwur8nj.fsf_-_@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877dwur8nj.fsf_-_@x220.int.ebiederm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 29, 2020 at 11:46:40AM -0500, Eric W. Biederman wrote: > > There is a small bug in the code that recomputes parts of bprm->cred > for every bprm->file. The code never recomputes the part of > clear_dangerous_personality_flags it is responsible for. > > Which means that in practice if someone creates a sgid script > the interpreter will not be able to use any of: > READ_IMPLIES_EXEC > ADDR_NO_RANDOMIZE > ADDR_COMPAT_LAYOUT > MMAP_PAGE_ZERO. > > This accentially clearing of personality flags probably does > not matter in practice because no one has complained > but it does make the code more difficult to understand. > > Further remaining bug compatible prevents the recomputation from being > removed and replaced by simply computing bprm->cred once from the > final bprm->file. > > Making this change removes the last behavior difference between > computing bprm->creds from the final file and recomputing > bprm->cred several times. Which allows this behavior change > to be justified for it's own reasons, and for any but hunts > looking into why the behavior changed to wind up here instead > of in the code that will follow that computes bprm->cred > from the final bprm->file. > > This small logic bug appears to have existed since the code > started clearing dangerous personality bits. > > History Tree: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git > Fixes: 1bb0fa189c6a ("[PATCH] NX: clean up legacy binary support") > Signed-off-by: "Eric W. Biederman" Yup, this looks good. Pointless nit because it's removed in the next patch, but pf_per_clear is following the same behavioral pattern as active_secureexec, it could be named active_per_clear, but since this already been bikeshed in v1, it's fine! :) Reviewed-by: Kees Cook I wish we had more robust execve tests. :( -- Kees Cook