Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp210088lqp; Tue, 11 Jun 2024 01:58:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKYTzzdxBQ5Ce3Q3QOYYYFvwDW+Gxwd4ts8m9slo9/HvNHkzZaDp865Cs1YKHrzrz3NSiTGiDC1bc1vip7sxTiXVSTfhWgKtUsIK2cPg== X-Google-Smtp-Source: AGHT+IHV9hmJiFwpwiXQINZmTGMvSPt9095XXhrt1w4u11LA8WHHONXt6ZwsMCt+PzriabY36GPd X-Received: by 2002:a05:6a20:a114:b0:1af:59b9:e3ed with SMTP id adf61e73a8af0-1b2f96de772mr13303538637.5.1718096309497; Tue, 11 Jun 2024 01:58:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718096309; cv=pass; d=google.com; s=arc-20160816; b=E6qFZWMDjEPUN7yGx84vZUdi/elh7apOv5Bvn4fXBZ4ICvF5Gvbq3Iwd9AGrAPM1vu fTZcpySamhKATMC28+qRAunB4Xy7TqcmQYkY5uj9Dqubl3eKNS3C8s0n+fX14npPM7k4 jlyeIBXDIzqD+vOg4G0l74AyEnojvZ3b0tmhkVExmVybOcUbZpt2c9DabcVJOGb3wf+u XMRjYorLlXh6EfdNcQoykOCZhDdJ2oZCsD1BYtRUSseW45Jx0FY2Ke0jpnJFs3BBT9FI 6aIFNE2DVVgunQKaxIkZYRP1LeC6TjNIeHuaGh0/h25TYXW/aJ4o4CHUhhb2vOXEY71k PZAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7HhB4sE7NSHxAQDCrk3KUOzkf7diWu3HyUqm9CqHvEk=; fh=BmBdvD6mRtIiHw3iEO8+ixxrD/ShRVjpzk+Z0v+XMZg=; b=tY0qtOfPclRIQpt5nFVSUbhXi5DaSXdvca3K01IjC3ArS8p+SAMxItIdfbUtx60SsC jeacSyzYRj/9wXbLdtmmGHruKoq4IIcpQmBi7wU7Xs2vdK84qcBbnL76AcwFu+G3O32w vedlhveYxbqo0X+VoANWMtZzv2tVj/wFNp6yLbq+eypNOQpOGh6tFVNsl6ohPFgDOtY3 NBe0Y3BGPRX0F5fU62wU1EH2d5Gu0xMu/b4RKXzhDSvZ1hFAADKm6UtK08oStUtDSD9b a54fLASp3GnrS2uoUan3hbneQYe7c3uO6X0CcfJtHsbUKoDXYcxbgBa4y8hp+O2xbhj7 MDqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=et2xVbPX; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-209468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209468-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-704322a1083si4453610b3a.360.2024.06.11.01.58.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:58:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=et2xVbPX; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-209468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209468-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1CA3CB28B38 for ; Tue, 11 Jun 2024 08:25:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C609174EF1; Tue, 11 Jun 2024 08:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="et2xVbPX" Received: from smtp-bc0c.mail.infomaniak.ch (smtp-bc0c.mail.infomaniak.ch [45.157.188.12]) (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 1215E3F8C7 for ; Tue, 11 Jun 2024 08:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094343; cv=none; b=ugCND+2tToxfQy6S9ln2YEyZNCA9GjJrj20qwkOzXD67xO+loYFHj8IbyPGB7doti4mlCDNk+X0Wtq3K924t8qUdLiqqAen+UzdvICEQamgfdT7VdkY0qMXgKfbO4oTbAE57rEu9SWVXo0fXpq94yFUnbXNPE7ugjDOP0WPg+RU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094343; c=relaxed/simple; bh=DyfZMNqfbelowjKg7Fg2Zw3jpBlT2GRYPwzy3WhZrVY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PmYaRna5Kwp80nj9MHH4PUzuJO37KxSRd5W0OP8oUFkC3nxVCeZBIke2A5Gmc6LetcTWTs89tiYdZIucKR1z4S/IoaF9CupRDvH73i2o2Keebdx3Ghn4DTjfQPupm9pwsVdgaTxfdADD4DNjje5RM7RUVyvK2UqedAO71IPw9XI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=et2xVbPX; arc=none smtp.client-ip=45.157.188.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4Vz1mH1BnxzmBh; Tue, 11 Jun 2024 10:19:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1718093951; bh=7HhB4sE7NSHxAQDCrk3KUOzkf7diWu3HyUqm9CqHvEk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=et2xVbPXxCumQmIsI+DjulepJsWh1kePvzlLTh4VmveVuXji/VJMRwDKZ3SrExvKX gB5KaN1tbWKEs1gfnEsT9+mhjcY6BXpSapxm/IjeqIl+fslwsbZvLtl1qjnOZWtbhT dU9ltWH1xnmMN0+1OKYI+k090IpP/lU8XYhZ66o4= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4Vz1mF6P1kzqRS; Tue, 11 Jun 2024 10:19:09 +0200 (CEST) Date: Tue, 11 Jun 2024 10:19:06 +0200 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: Jann Horn Cc: Tahera Fahimi , =?utf-8?Q?G=C3=BCnther?= Noack , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?B?QmrDtnJu?= Roy Baron , outreachy@lists.linux.dev, netdev@vger.kernel.org Subject: Re: [PATCH v3] landlock: Add abstract unix socket connect restriction Message-ID: <20240611.Eed0Oochaht4@digikod.net> References: <20240610.Aifee5ingugh@digikod.net> 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 Content-Transfer-Encoding: 8bit In-Reply-To: X-Infomaniak-Routing: alpha On Mon, Jun 10, 2024 at 11:49:21PM +0200, Jann Horn wrote: > On Mon, Jun 10, 2024 at 6:36 PM Mickaël Salaün wrote: > > On Fri, Jun 07, 2024 at 01:41:39PM -0600, Tahera Fahimi wrote: > > > On Fri, Jun 07, 2024 at 10:28:35AM +0200, Günther Noack wrote: > > > > Is it intentional that you are both restricting the connection and the sending > > > > with the same flag (security_unix_may_send)? If an existing Unix Domain Socket > > > > gets passed in to a program from the outside (e.g. as stdout), shouldn't it > > > > still be possible that the program enables a Landlock policy and then still > > > > writes to it? (Does that work? Am I mis-reading the patch?) > > > > If a passed socket is already connected, then a write/send should work. > > If I'm reading unix_dgram_sendmsg() correctly, we'll always hit > security_unix_may_send() for any UNIX socket type other than > SOCK_SEQPACKET (meaning SOCK_STREAM and SOCK_DGRAM), even if the > socket is already connected, and then we'll do the landlock check. > That's probably not the intended behavior for Landlock, unless I'm > misreading the code? > > Maybe to get nice semantics it's necessary to add a parameter to > security_unix_may_send() that says whether the destination address > came from the caller or from the socket? I think it would make sense to ignore connected sockets with security_unix_may_send() because it should already be controlled by security_unix_stream_connect(). This would still allow passed/inherited connected sockets to be used, which is an important feature and would be consistent with read/write on other passed FDs. This would not work with dgram sockets though. We need tests for this case and with different socket modes (inspired by the net_test.c:protocol variants).