Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp928485lqd; Thu, 25 Apr 2024 00:24:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWh1aIRu6BVV+xPMyM86ehjn7KTBlFgIfDGaCJIkzzqQAECGrlCfTpYDPUjMgsc1+AvGX3IIiOaNa04Yq0ZJ7/AYfeFkR1qYPrB/d9dIg== X-Google-Smtp-Source: AGHT+IEw+g6jcPI1rV+mt7ONoZqKlXyJr68O2QMCAwxl82nto2R+1NGWahJ5XD55JO34TguJxH7H X-Received: by 2002:ad4:404c:0:b0:6a0:582d:496d with SMTP id r12-20020ad4404c000000b006a0582d496dmr5698630qvp.53.1714029899091; Thu, 25 Apr 2024 00:24:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714029899; cv=pass; d=google.com; s=arc-20160816; b=u3h/pxLGd9iGZICRwSl2SSnIafACTFfmQPCPxIHK+o4H10/Bqbk8moOaA6XTDKZRyZ pGw/B49BOTgOXmzoYaRmzYzkhgMzYSHrP/3p/6c65C8BR4JEEP1z26edpBH1AJu/PnEW +mSJt+cLt+/y62cGT6PTNk3wP8sQRgaQuLO2w0gPo7Nar8RhYYAhGeNlOWoHZ0fyYQfi M9WU1ghjt9J2fswWQwhqT8l0nNM0YlW1isjGTJR9gNCsIouRIh+NJqTpBua9zmrX1dz/ TgA04HnbzCd+FOuBu1gjjOemHahanFdDaH79PFbhIzTIUdDcLJYtn9t9+hoo/dBi60SZ qmVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=jLLUQDrLxe3HEYl361v9/pXQdC+WWf+JkjjMbghvWPo=; fh=ASmaM0ygBElHolOvmPrpgrvhL0MBWxI1U/hBq50wztw=; b=dsgRd/znjQeMVIj53g83Iow/5WC7p1omO6TZbaNbkCeGMFCd4ld8r3snwTlepwYuo3 ptwO2MNG7bnVxlLJF/2TimNqOaFKXhy/LtQgs3NhjG6jPs1nvKGrQZujDfZcAghgdxe+ XhHIPpEXLEb0OZhlBg+g9J2r73J2a68fFLJMaRZC8HVKtb80bYd57RoopdzweVkaRyA2 Mlnu1V5Kl50kd1H6AnOp3NoC1gY4hVZ42ArDMM5CQqrHj6/temIfzcPy8ZQGrRQKwgGE wyRYdunsjMaaTzIkx85ZhhrTRYNbWZ755de7RSc7zC2Ez0c6nb6rFNfB4mMGcaCL4ULJ 6T2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=hdam2PgX; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-kernel+bounces-158121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gu15-20020a056214260f00b0069b4fe0611bsi17555127qvb.280.2024.04.25.00.24.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 00:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=hdam2PgX; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-kernel+bounces-158121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A244C1C23BEE for ; Thu, 25 Apr 2024 07:24:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1D836D1A0; Thu, 25 Apr 2024 07:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="hdam2PgX" Received: from forward500b.mail.yandex.net (forward500b.mail.yandex.net [178.154.239.144]) (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 10C556BFBC; Thu, 25 Apr 2024 07:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.144 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714029888; cv=none; b=Dv4AuYmTnRILTf1LKYTzcoqa2RFW+Wwp4326zX3Yn5hSCwy35O3WRAOWusEU0UfgL0l6FbFd8ooK6RJi7RfyHlNL5WO8AmPTh0/QHVFYyBO4NBCc2V9qYPJOkA7E21mzvSQX0Z8hcIxUYgqSx1cH1EV+1xJqBIMFITOBD/5vB/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714029888; c=relaxed/simple; bh=CjtZI7wWLGqJ5+XYn8iIRWrfe8W/XZ94e7ffMamGKvo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qBCco4SMGDJxzQME/jfL40q3JOk3Y/rGU/KAwfcHNIjkqiC6U2B/gzqSsOd2+cm9JcHhUB7T/91/h0tctWwKicLSqVGnngZjSqac2YPKGYZMg/QWzrDSvC053+tjnYBczW5sdTE8QnWBRcJZtRSpi7VOMVunXhn8BIFCfT29Raw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=hdam2PgX; arc=none smtp.client-ip=178.154.239.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:4d9c:0:640:f3a0:0]) by forward500b.mail.yandex.net (Yandex) with ESMTPS id 8C8A16162D; Thu, 25 Apr 2024 10:24:40 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id bOG6gGioGOs0-jNjVOVWO; Thu, 25 Apr 2024 10:24:39 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1714029879; bh=jLLUQDrLxe3HEYl361v9/pXQdC+WWf+JkjjMbghvWPo=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=hdam2PgXB6ee2zxNRoaWK+rJfrp3ym/nhzEXaTE61WP6EANyBIAZU/gKxSs9cgOtv ncys4KZq1HSKNpVOcaW/l5rEkTzd8xFE/2GAZqNhk+TvZfJuOc5cfEHRQmaUd1iua0 ua/cqByIHDk5CtWx5tVOjPX3g3UxV1mS499vCs7w= Authentication-Results: mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: Date: Thu, 25 Apr 2024 10:24:37 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] openat2: add OA2_INHERIT_CRED flag Content-Language: en-US To: Al Viro Cc: linux-kernel@vger.kernel.org, Stefan Metzmacher , Eric Biederman , Andy Lutomirski , Christian Brauner , Jan Kara , Jeff Layton , Chuck Lever , Alexander Aring , David Laight , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, Paolo Bonzini , =?UTF-8?Q?Christian_G=C3=B6ttsche?= References: <20240424105248.189032-1-stsp2@yandex.ru> <20240424105248.189032-3-stsp2@yandex.ru> <20240425023127.GH2118490@ZenIV> From: stsp In-Reply-To: <20240425023127.GH2118490@ZenIV> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 25.04.2024 05:31, Al Viro пишет: > Consider the following, currently absolutely harmless situation: > * process is owned by luser:students. > * descriptor 69 refers to root-opened root directory (O_RDONLY) > What's the expected result of > fcntl(69, F_SEFTD, O_CLOEXEC); > opening "etc/shadow" with dirfd equal to 69 and your flag given > subsequent read() from the resulting descriptor? > > At which point will the kernel say "go fuck yourself, I'm not letting you > read that file", provided that attacker passes that new flag of yours? > > As a bonus question, how about opening it for _write_, seeing that this > is an obvious instant roothole? > > Again, currently the setup that has a root-opened directory in descriptor > table of a non-root process is safe. > > Incidentally, suppose you have the same process run with stdin opened > (r/o) by root. F_SETFD it to O_CLOEXEC, then use your open with > dirfd being 0, pathname - "" and flags - O_RDWR. Ok, F_SETFD, how simple. :( > AFAICS, without an explicit opt-in by the original opener it's > a non-starter, and TBH I doubt that even with such opt-in (FMODE_CRED, > whatever) it would be a good idea - it gives too much. Yes, which is why I am quite sceptical to this FMODE_CRED idea. Please note that my O_CLOEXEC check actually meant to check that exactly this process have opened the dir. It just didn't happen that way, as you pointed. Can I replace the O_CLOEXEC check with some explicit check that makes sure the fd was opened by exactly that process?