Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1232988iob; Thu, 12 May 2022 14:25:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuKEOdGSCj1b1yhcwzcuceZcREFV3z5ptR609wplBay+8/Yc4kiFFIMHpF9vvBpZBGQ+Ix X-Received: by 2002:a05:6a00:1252:b0:50e:9fc:d5b7 with SMTP id u18-20020a056a00125200b0050e09fcd5b7mr1444855pfi.85.1652390712752; Thu, 12 May 2022 14:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652390712; cv=none; d=google.com; s=arc-20160816; b=sKR/9ljwqgpuKkBRiZZhbck91Oku94IAoDiGe+a39SrETCEP+4bhJ7cei/kSN86HcA QPfvobs1LupK47Nn3KJBAfEUz1ZmqNfEVW9V2FB8oLoQQtdy25bRX1i9oEoWmXQ06+5m rHvxf3TCBKckps3JinzEon5YBBzmRsmISVz56sfBMcjvHC2vP/QFEu4kxGzn1iDem0De yZppgK67tEJIlIFMTjxJudlHfC7d90Ea9UUNT2qGtmzrPP5ruS7bBFnWxAkaGFeSuERv DA/cGXaFODuhWCCq8SpI8KpJJAVELF5FKBPnxdhmELT2mA11kcYRUIjU71apQi6+RQRw ufrg== 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 :feedback-id:message-id:subject:reply-to:from:to:dkim-signature:date; bh=7NmTfOCxDVAfqJ/9f/2B3RstZoJLD303Bp1OuJZ4KeA=; b=ZW2vyDE+y2mQpXL1H5UQnj2cw+4kk8/NDZfz//Fxm02OBg8PX63+4Fz09WvIrI1MrC bcCdVv1gaa+HqGKB3WPtH0cPDxkFeYKgujUU+YVj+yvJP0a0EXPFmLcNmPu/7i7oe6O+ hDk7UhTU+bp0Dk4QUCn3lMBzxDC5ARIK7eXp9dezOxTYv2cK3yGCh2Md/7qxgLZSTAQx FF35ksUzXTEwv3wp/SCaf1FNvtHpYmXrskymhUk5BenxXIMvwZ7zWVq92l1s1AtPZBVb AB2GpGlR2V7toAdAwQNJMPn5GUhaDSoNIqO7k1dHGF6y38xm5x+ybekffGTziS2LUbe3 M+MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@emersion.fr header.s=protonmail2 header.b=f02r2AQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=emersion.fr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gj14-20020a17090b108e00b001ca97924abdsi773668pjb.115.2022.05.12.14.24.32; Thu, 12 May 2022 14:25:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@emersion.fr header.s=protonmail2 header.b=f02r2AQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=emersion.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352709AbiELKiQ (ORCPT + 99 others); Thu, 12 May 2022 06:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352683AbiELKiJ (ORCPT ); Thu, 12 May 2022 06:38:09 -0400 Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 022D45DBF1 for ; Thu, 12 May 2022 03:38:06 -0700 (PDT) Date: Thu, 12 May 2022 10:37:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail2; t=1652351884; bh=7NmTfOCxDVAfqJ/9f/2B3RstZoJLD303Bp1OuJZ4KeA=; h=Date:To:From:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc: Date:Subject:Reply-To:Feedback-ID:Message-ID; b=f02r2AQ9t/AYTiq+emcHSWiFf7xzC6rrO/toal82g03MsexLkvGgplJ0P5CKchR8S g4eoOKwjW1BQR8oTTpIl47owvv8yGQCYGhmfVO9EnqRx5iHVzi0kZ7Vd6xopnD5UcZ dmKBGRYEkFpP90/ZrWYsrJvwiQbUS8p2z4CAi0p7AlMvraDeer8W6IFjEYiz0wo5Nq A1sDfALlDtQXUoeNAt+KeLNLtxDfqJ5MSh2K8o5ghWwJquNznQyhB4aWo0o9ftN49N mFCs0jrkfBpCbz4eWI8b2x/aWtWhZA7OXni+hP52rheqU8StS77chUp8xhBxbmoEuP Ccbjj/059/lcw== To: "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" From: Simon Ser Reply-To: Simon Ser Subject: procfs: open("/proc/self/fd/...") allows bypassing O_RDONLY Message-ID: Feedback-ID: 1358184:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, I'm a user-space developer working on Wayland. Recently we've been discussing about security considerations related to FD passing between processes [1]. A Wayland compositor often needs to share read-only data with its clients. Examples include a keyboard keymap, or a pixel format table. The clients might be untrusted. The data sharing can happen by having the compositor send a read-only FD (ie, a FD opened with O_RDONLY) to clients. It was assumed that passing such a FD wouldn't allow Wayland clients to write to the file. However, it was recently discovered that procfs allows to bypass this restriction. A process can open(2) "/proc/self/fd/" with O_RDWR, and that will return a FD suitable for writing. This also works when running the client inside a user namespace. A PoC is available at [2] and can be tested inside a compositor which uses this O_RDONLY strategy (e.g. wlroots compositors). Question: is this intended behavior, or is this an oversight? If this is intended behavior, what would be a good way to share a FD to another process without allowing it to write to the underlying file? Thanks, Simon [1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/92 [2]: https://paste.sr.ht/~emersion/eac94b03f286e21f8362354b6af032291c00f8a7