Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 00E6E23AF for ; Fri, 3 Nov 2023 15:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yPay8q/B" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46CD71BF for ; Fri, 3 Nov 2023 08:57:33 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5b053454aeeso30968517b3.0 for ; Fri, 03 Nov 2023 08:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699027052; x=1699631852; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=IbaLdXXaJft3PAESOyQ2DzFlwpnmFnuqs4CJYMz+eV4=; b=yPay8q/B+VOK9WOgj5KQbeZ9IP8v3IzrUZdoItR48mGoNKO9V8nSqdnb59du5Y4ov+ faG7vEwawGf8hIucNJMTcp7OP5AYrUe8rWHBTjX4x3eNgck+sb3X+6UgJRj+9+b6AnOa PeHlIbszQPdZnTDWl5BA1Ymdpf00ElPLUOXmlSOkyB2jSdb8kn3nPy2Jf2ICTGCVNF6U 9Nk8GXnOGI5xm1bNiFh7xqXIMIK47FzWeGaEckWff90Ek3G0YatFJJx2QP1lec0Y0owP m+FdhVq97ISCWmkteMTCPw5/yO+GBI/EtuNMTb5vgJjXwIRzWDf9EwTpkR3Np74oFIox I+SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699027052; x=1699631852; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IbaLdXXaJft3PAESOyQ2DzFlwpnmFnuqs4CJYMz+eV4=; b=Nq4aEVeGDAykt2D8FbQmet7CV989uP73n3NmjvW1W+VuL9x/KRVmm6vGe86DkpFgjl 1aByQ6X++ZifIWsCKqYaAgMesL88UvxsHkZzECpNT4WWKj/Q8tBbVIOJQFDIaQW91I75 LeywEKOL2/hu1+veIt83lCTomrl0Udp6/aCBAxRqmdPbiq3JiLfimOdTkLJajccE4J+k FPhxXeSkXdhzIggLnc47OxwOPZ0wm6wwIByAxDtWf3y0LwViMTpm6dwzzvzTWfGxEziE QuFNksqRf37sJO2a9rkgjxmP4NIOXkW3jitp4HoEHF5dhE9tYy3Xbt1va3TgPMkRtdvS Lm+Q== X-Gm-Message-State: AOJu0YyOm9aCrJ7Nbr9pvQ9oEOT+TL3mOfA299mIl2adbbpwlrWgpjfu oIY3TU8Iqr/sY/wxl/pyYkzwj2r+2bM= X-Google-Smtp-Source: AGHT+IFk+I+Ye72iIjCcAjhno+EFM4iIjjCtWmKcVbVOsxQf8EcbCGYSTnrjkDd+N4VpszlRmfHFOdHcvWE= X-Received: from sport.zrh.corp.google.com ([2a00:79e0:9d:4:7ddd:bc72:7a4a:ba94]) (user=gnoack job=sendgmr) by 2002:a25:50d2:0:b0:da0:5d66:4ded with SMTP id e201-20020a2550d2000000b00da05d664dedmr410231ybb.2.1699027052454; Fri, 03 Nov 2023 08:57:32 -0700 (PDT) Date: Fri, 3 Nov 2023 16:57:10 +0100 Message-Id: <20231103155717.78042-1-gnoack@google.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 0/7] Landlock: IOCTL support From: "=?UTF-8?q?G=C3=BCnther=20Noack?=" To: linux-security-module@vger.kernel.org, "=?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?=" Cc: Jeff Xu , Jorge Lucangeli Obes , Allen Webb , Dmitry Torokhov , Paul Moore , Konstantin Meskhidze , Matt Bobrowski , linux-fsdevel@vger.kernel.org, "=?UTF-8?q?G=C3=BCnther=20Noack?=" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello! These patches add simple ioctl(2) support to Landlock. Objective ~~~~~~~~~ Make ioctl(2) requests restrictable with Landlock, in a way that is useful for real-world applications. Proposed approach ~~~~~~~~~~~~~~~~~ Introduce the LANDLOCK_ACCESS_FS_IOCTL right, which restricts the use of ioctl(2) on file descriptors. We attach IOCTL access rights to opened file descriptors, as we already do for LANDLOCK_ACCESS_FS_TRUNCATE. If LANDLOCK_ACCESS_FS_IOCTL is handled (restricted in the ruleset), the LANDLOCK_ACCESS_FS_IOCTL access right governs the use of all IOCTL commands. We make an exception for the common and known-harmless IOCTL commands FIOCLEX, FIONCLEX, FIONBIO and FIONREAD. These IOCTL commands are always permitted. Their functionality is already available through fcntl(2). If additionally(!), the access rights LANDLOCK_ACCESS_FS_READ_FILE, LANDLOCK_ACCESS_FS_WRITE_FILE or LANDLOCK_ACCESS_FS_READ_DIR are handled, these access rights also unlock some IOCTL commands which are considered safe for use with files opened in these ways. As soon as these access rights are handled, the affected IOCTL commands can not be permitted through LANDLOCK_ACCESS_FS_IOCTL any more, but only be permitted through the respective more specific access rights. A full list of these access rights is listed below in this cover letter and in the documentation. I believe that this approach works for the majority of use cases, and offers a good trade-off between Landlock API and implementation complexity and flexibility when the feature is used. Current limitations ~~~~~~~~~~~~~~~~~~~ With this patch set, ioctl(2) requests can *not* be filtered based on file type, device number (dev_t) or on the ioctl(2) request number. On the initial RFC patch set [1], we have reached consensus to start with this simpler coarse-grained approach, and build additional IOCTL restriction capabilities on top in subsequent steps. [1] https://lore.kernel.org/linux-security-module/d4f1395c-d2d4-1860-3a02-2= a0c023dd761@digikod.net/ Notable implications of this approach ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Existing inherited file descriptors stay unaffected when a program enables Landlock. This means in particular that in common scenarios, the terminal's IOCTLs (ioctl_tty(2)) continue to work. * ioctl(2) continues to be available for file descriptors acquired through means other than open(2). Example: Network sockets, memfd_create(2), file descriptors that are already open before the Landlock ruleset is enabled. Examples ~~~~~~~~ Starting a sandboxed shell from $HOME with samples/landlock/sandboxer: LL_FS_RO=3D/ LL_FS_RW=3D. ./sandboxer /bin/bash The LANDLOCK_ACCESS_FS_IOCTL right is part of the "read-write" rights here, so we expect that newly opened files outside of $HOME don't work with most IOCTL commands. * "stty" works: It probes terminal properties * "stty