Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp976821lqs; Wed, 6 Mar 2024 02:32:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUyqYI/d2na6Y5hHRFigA4tFUeAsbmB1Vq3foAA2z/bmbpxnGcnrVoD6BxlMj6poeZ5srsD8nAHPQrTjmDVnreV5y6gUqQnzX2Kf7nO9w== X-Google-Smtp-Source: AGHT+IEsq/dVVc1kfE90l2HO+AcccOmkUHN5st32xDceIrpgoDSqnfng6AjSW+qyL8h7qw2nA4/h X-Received: by 2002:a05:6808:2095:b0:3c1:e70d:7c54 with SMTP id s21-20020a056808209500b003c1e70d7c54mr4956030oiw.53.1709721152119; Wed, 06 Mar 2024 02:32:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709721152; cv=pass; d=google.com; s=arc-20160816; b=jyaMp/xW8AbdNs7Usk3DfFtnHHOAbxSSPy5plEl8GMf1dqj9e5yu97oeUttLbIyJ3v FzyDUdkSwGNPktf0HBy5C2kPb0eUn4fR2yCRZ/xq77ej+eB/sGBtAaj3SV33TvUZDyTn IZmcqt6Ae9KZeUF2NZFr9tqYpxSVGFU3H4X7RMJw4+txUUx/hFY1TXy8z/KoRu8eexLi 2PXUC8FbCR2xZLtn/UqTzPHiI2e55yzVkBB4HnhQWKVcvEn16a5isNZkkP5anywjZnj6 2Oilpu1kMLUQAUJzKyMIS4H/e6W+tov/x9RSASmJS7HPjX0R4ZNcnAYvsV+AcSwKlEqt /5hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qa8JdVSpnBoAM9AkvTBCRg4tj2etUAO4KewHW1t05eo=; fh=OYiTjqxzPcb6DO9vFXC+EhjiuV3mplms8/+SBUqgELw=; b=a96pv5S9E2QuGq2xF0AplkojiCHTBK2WFnL+bqQzlNaZC14C94Jp/h12YIp6D+5/qs Z2xSPLRd8QQ4v7pu75PH4rxEpPqELZu41TGFssWqXQJB/zJy2CL6e2rmwMXDmof1+zFg lil6CyaYfjH9sdKyXUHw5W06SNip7N1HeI0Pgof7KnYdPDl7cRPBhEmAFnZE0+i/y9D4 n7wQ8mD3D0zkvuYkIUKOrM3hDPIj2rCBmG1QdukkFIzQ/qVDGgOdpUAFa1Jwe+Nfpe+x SqwFkuZEWjfIvLnEYLkZ764Z8sSxRWTgBGPh681wu99akZJO4Jvhat4BzfmIzoIsjv9l zJ9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bpmesp3C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-93766-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o36-20020a635a24000000b005dc6d15c299si11911672pgb.240.2024.03.06.02.32.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:32:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93766-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bpmesp3C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-93766-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 913DB281080 for ; Wed, 6 Mar 2024 10:32:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88CEA605AD; Wed, 6 Mar 2024 10:32:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bpmesp3C" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5CB35D8E5; Wed, 6 Mar 2024 10:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709721119; cv=none; b=DL9LJcMA3lrKDJJhzJ0UIzrT/GZcsgGnTLBTq1aIJXo1u8GqwHINMyJruWmL3OOlvepTfzNUkqB+WQaGUFsym5KbwpAPKjYmChlKFhiikZEI/o7/9YNe3xekQNY7PByiMwEIjgRSoO/Nvg3QXQVLxW3aKJI4p+uZPxFpi79K03M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709721119; c=relaxed/simple; bh=V9dupUdmdDT6oqMU+vmjgEz0vS/DRI+SFGdX0PtriQ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=loFToO6NXIfuxGBAkl+JOpq419XkiKQo/NAGC5FASkzqIE7JgWJN6IovV3/5wjJxfROpEQdefppWhflJUCDD3xJyUJ6EHJkvTnccyLPcHELHoJpSt55RCeE5sDaCdye519auo3rBsjEA5vx0NElllrpc8MMSfYJfLToq+cFq+Aw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bpmesp3C; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDC6AC433C7; Wed, 6 Mar 2024 10:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709721119; bh=V9dupUdmdDT6oqMU+vmjgEz0vS/DRI+SFGdX0PtriQ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bpmesp3Cf3UOtm/WOXArUNMhwaWIE02nRlh4xtXs3Lh+cjLxTwDyVb9a7EvRli1OH V3yOaOwtcial4MmChZfRxrsm5JPUEFQq6KidAXXVD09QgVJ8RxrvaMAYAVfdx4VkrH 01uPTpsgVgwNB3vv3U4JgFPhbAfJ4UgBVO93iaCx3vdYAmvjAKcX4IKOBno+pfFc3a MlI41Sof4sfd5ivtkmsxMdrD02aBRPp7ctv6JnaTC/ItG8SYJaaLIiTmUFJ2W0VQVE SapT+bLxNol8QCCptrm5K0aM4EzjhsOUcDw0rsD+19VyhhKgHSb/2a9uRbqDmlS0JO /figxLtEqJODQ== Date: Wed, 6 Mar 2024 11:31:53 +0100 From: Christian Brauner To: Kees Cook Cc: Adrian Ratiu , linux-fsdevel@vger.kernel.org, kernel@collabora.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Guenter Roeck , Doug Anderson , Jann Horn , Andrew Morton , Randy Dunlap , Mike Frysinger Subject: Re: [PATCH v2] proc: allow restricting /proc/pid/mem writes Message-ID: <20240306-titan-gerade-6e3bbb057213@brauner> References: <20240301213442.198443-1-adrian.ratiu@collabora.com> <20240304-zugute-abtragen-d499556390b3@brauner> <202403040943.9545EBE5@keescook> <20240305-attentat-robust-b0da8137b7df@brauner> <202403050134.784D787337@keescook> <20240305-kontakt-ticken-77fc8f02be1d@brauner> <202403050211.86A44769@keescook> <20240305-brotkrumen-vorbild-9709ce924d25@brauner> <202403051033.9527DD75@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202403051033.9527DD75@keescook> On Tue, Mar 05, 2024 at 10:37:20AM -0800, Kees Cook wrote: > On Tue, Mar 05, 2024 at 11:32:04AM +0100, Christian Brauner wrote: > > On Tue, Mar 05, 2024 at 02:12:26AM -0800, Kees Cook wrote: > > > On Tue, Mar 05, 2024 at 10:58:25AM +0100, Christian Brauner wrote: > > > > Since the write handler for /proc//mem does raise FOLL_FORCE > > > > unconditionally it likely would implicitly. But I'm not familiar enough > > > > with FOLL_FORCE to say for sure. > > > > > > I should phrase the question better. :) Is the supervisor writing into > > > read-only regions of the child process? > > > > Hm... I suspect we don't. Let's take two concrete examples so you can > > tell me. > > > > Incus intercepts the sysinfo() syscall. It prepares a struct sysinfo > > with cgroup aware values for the supervised process and then does: > > > > unix.Pwrite(siov.memFd, &sysinfo, sizeof(struct sysinfo), seccomp_data.args[0])) > > > > It also intercepts some bpf system calls attaching bpf programs for the > > caller. If that fails we update the log buffer for the supervised > > process: > > > > union bpf_attr attr = {}, new_attr = {}; > > > > // read struct bpf_attr from mem_fd > > ret = pread(mem_fd, &attr, attr_len, req->data.args[1]); > > if (ret < 0) > > return -errno; > > > > // Do stuff with attr. Stuff fails. Update log buffer for supervised process: > > if ((new_attr.log_size) > 0 && (pwrite(mem_fd, new_attr.log_buf, new_attr.log_size, attr.log_buf) != new_attr.log_size)) > > This is almost certainly in writable memory (either stack or .data). > > > But I'm not sure if there are other use-cases that would require this. > > Maybe this option needs to be per-process (like no_new_privs), and with > a few access levels: > > - as things are now > - no FOLL_FORCE unless by ptracer > - no writes unless by ptracer > - no FOLL_FORCE ever > - no writes ever > - no reads unless by ptracer > - no reads ever Doing it as a prctl() would be fine.