Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp166458lqp; Wed, 22 May 2024 00:07:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0ZAm+QS5b6h6OyqLEcemZYcXQcAR7IOdHj3C5GTJ5K1+ptrwLLQAParjjPNdRwVyjXl7vFmV2HE+ygKGSuMvtJfA5D/hAea02T37hiA== X-Google-Smtp-Source: AGHT+IGt+sjMvdreF3Z/gpof4UKuW6W5J1bEPy0p+ZtAe0Z4pRQqVcCAHWPPWfC+YwPIGH1BkkVh X-Received: by 2002:a05:6a21:616:b0:1b0:14ee:3b27 with SMTP id adf61e73a8af0-1b1f881f8bfmr1595151637.35.1716361622294; Wed, 22 May 2024 00:07:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716361622; cv=pass; d=google.com; s=arc-20160816; b=0IDOLD2NqE09g2KhsypAATtEHkEcvrU/OPiMWwHo3xIeKwxbcJHEAE/cqab+wI4IPj IEClebuUagOb7oC/8Os7s41mkfNLdRNNkjhmlfbnxepwUgxDnrVygmMcGNNo8f34mb4R t3KDTs5WzQCjCakWxYSXsqtgTKFD2Ki/9fpfb5t7VW1WPGWxwYH/xv/QTGWNTy4NQNS4 ypRD0TIBzBiF7FlGe9hJM9Taq5F14yLV8b9lelOOvHHoHj2yHWm/A1l9gX5rl8rAgA6i vyNldr9TbLxjI87oD0WsKl/pY0JeWQ+Iou/rqHroNOsO4qo2vMWQUqP7YLEI/IR805VA SWzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=7DiScAt5S4ywxHN3dM0N7e6SR+dsj1XmtD3cPD5hzZs=; fh=xpIxUkm+cc2HcSme/zIFeEYqjJDTPyYfVLSYSMP6Ryo=; b=PSaXT39NXlPYUHGDZxIZs0WXjLFGWDa2WC7vX79N7jdUEv8mNw22hao76xyyJscZDZ 5zUctr1gP421Nm9gWQMrtGGUCiycyt7QOLHf0vJmhUi3GeEL9KA8ss+HSxqyJ/arBHCd LqGYwzYFZvBjoPNXR823fpSB4OPLUpr90dmVnhL4lg0fy+QVrbCkYWc3n9xupV7QQS3J nbeKAUJJ1DEZ/lQO5aLigvCBwVT0K3ermzIrqZHHfkVveWqTKbOH4VB5RQzgA8Ovr0JX 33LqluaY5X7RvCBMD3DvLKvpXRg2N59W+J/LxcD3oPq3B+7hOlsIOrhurdJoXayiqs+T hO7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CMt2YLAe; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-185837-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-65d0a1338c3si2282352a12.159.2024.05.22.00.07.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 00:07:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185837-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CMt2YLAe; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-185837-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 C233EB21875 for ; Wed, 22 May 2024 07:06:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C97127BB06; Wed, 22 May 2024 07:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CMt2YLAe" Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 915C944374 for ; Wed, 22 May 2024 07:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716361610; cv=none; b=CAqa0eLFk4ptpZuIsrt5uOVwQW+covsGkoP7f5SDZRvaKtl0sevyc9JEnf4HeKxmsHvmyClXoLCqa9WVf0YStf0CNpK1qVw5xjrV6G9HUhPynl3gOGR/DvwtbBIdNV5poKCJQTUZMERHSCn3ZgM8LohnlpTNC0Xn/OKTMK2Yyr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716361610; c=relaxed/simple; bh=WwISwpMFMwJIC6EppTp49QjaUSjX9f1RPAknL9LHWIU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=TZuRdBXnGHOy7FHwVvI886wR5VFAmZDIXY7WE/6xaZNACXciL+Xv0jZINpRYFICnDUCddPER3fqnap8NfX7INon1owDh77AbGH6KFjTHUC7fRso46n4OgMLZ4vHaYfIj4sALEZ+Fx1pbLKgCOuFp1ChwLE1dpV9fjTLqriksecc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CMt2YLAe; arc=none smtp.client-ip=209.85.160.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-248f7fdc323so2218129fac.1 for ; Wed, 22 May 2024 00:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716361607; x=1716966407; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7DiScAt5S4ywxHN3dM0N7e6SR+dsj1XmtD3cPD5hzZs=; b=CMt2YLAe63Q9YkddIafQlswbXcV0fidr/NqGrp9/lYjTc2Tu/Qw9GlqUh3geu2Z/na U0sxLPKnG5lFEBYRe5JXx4sHghzgIpVW0QLOxOu9Cp5+oiWW99v5MOLws/qp7g6+OyXU 4dnjBJcAwaoBYfJtUxvG1O5+zo9Cj01R8rx0jKj6VU239Qk6VfJjxHoKs7J+5Yxr0ZQG /UkWZztTZ3LxTnpE5qhGTCUxvU4HaffRWRJgpPIQvyz8z7KsA/LOFqWgGXenLXrL6ptc DHAvJ7tExj1c0DPpCVgYIly9FCZ/CnwvkUDR5qwj/v4DgCryUEiVJotHylY/v2XfZ1gT 1Gxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716361607; x=1716966407; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7DiScAt5S4ywxHN3dM0N7e6SR+dsj1XmtD3cPD5hzZs=; b=GUaTs5Kz9Mz7T3BM0lLJeXTwvCLSoW28tMitL/IfbKGUSnDBbo6B5B96uqYRojx7JV Xmd7BGifMZST+Ih4Dmy1PjAJ11ToMktIQCfc1I1DjmAYoelLldNjYaH/pD+8wYM3y9RX /bhwjrEzanZVdPlJwAQT4msfCQQ4Ax6Ard+O9Xkkr7VOyaPI6eU3QYhyzS4xIkacBj6r Hi+ggOjx5vuhF0yUfXDcYWFpjoVyo1Z+FjICW3ELDpSIQMpX1hqF1LCvlsYcIBBAXU0C eCx5qmdReOoE5ovyX57tF/aEC96gE6gbxD/pQuvM9NYlnWwzXKr2Qve+5e9X96Hq72Co Po2g== X-Forwarded-Encrypted: i=1; AJvYcCVL8m1LHQfEI5VbgbvzzWWcEDGA3RD7qjjszuxy01LBf7NIgUtZm56wwdWArr1r312/KgEGFRbumj3e/pXHsP8rVP0jWzoDGcYBLkb2 X-Gm-Message-State: AOJu0Yxx2wdlw9uUxMfheDdZcwiW2E37wi/QsCAj42DVAQy7Feqkza8D 1EUWJuqCP6iCzGP6Hkd59qqNryE9Tae7EH+HuonxU/q4xk79Y9aaSPSJ+WAGdl0WKYDQHCyTKad ZSz/yyMNwDysi/8zJXU2pSbdyk9vpzzJJl2XC X-Received: by 2002:a05:6871:722:b0:24c:5dd6:97b4 with SMTP id 586e51a60fabf-24c68d23727mr2148874fac.39.1716361607356; Wed, 22 May 2024 00:06:47 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240514175551.297237-1-avagin@google.com> <20240514175551.297237-3-avagin@google.com> <20240515125113.GC6821@redhat.com> <20240516093427.GA19105@redhat.com> <20240516130913.GB19105@redhat.com> In-Reply-To: From: Andrei Vagin Date: Wed, 22 May 2024 00:06:36 -0700 Message-ID: Subject: Re: [PATCH 2/3] seccomp: release task filters when the task exits To: Oleg Nesterov Cc: Kees Cook , Tycho Andersen , Andy Lutomirski , Will Drewry , Jens Axboe , Christian Brauner , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > On Thu, May 16, 2024 at 6:10=E2=80=AFAM Oleg Nesterov w= rote: > > > > On 05/16, Oleg Nesterov wrote: > > > > > > On 05/15, Andrei Vagin wrote: > > > > > > > > seccomp_sync_threads and seccomp_can_sync_threads should be conside= red too. > > > > > > Yes. But we only need to consider them in the multi-thread case, righ= t? > > > In this case exit_signals() sets PF_EXITING under ->siglock, so they = can't > > > miss this flag, seccomp_filter_release() doesn't need to take siglock= . > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PF_EXITING is set without holding ->siglock if tsk->signal has the SIGNAL_GROUP_EXIT flag. I think it can be a case when one thread is in seccomp_sync_threads and others are exiting. The first thread can check that PF_EXITING isn't set for another thread. Then, the second thread calls exit_signals and seccomp_filter_release(), and finally, the first thread sets its seccomp.filter to the second thread. If seccomp_filter_release tak= es siglock, it will be handled properly. > > > > Ah, no. seccomp_filter_release() does need to take ->siglock even if we > > forget about proc_pid_seccomp_cache(). > > > > Without siglock > > > > orig =3D tsk->seccomp.filter; > > > > can leak into the critical section in exit_signals() (spin_unlock is th= e > > one-way barrier) and this LOAD can be reordered with "flags |=3D PF_EXI= TING". > > > > Hmm. I thought we have something smp_mb__after_unlock(), but it seems w= e > > don't. So we can't add a fast-path We have smp_mb__after_unlock_lock in include/linux/rcupdate.h. > > > > if (!tsk->seccomp.filter) > > return; > > > > check at the start of seccomp_filter_release(). > > > > > > Cough... Now that I look at seccomp_can_sync_threads() I think it too > > doesn't need the PF_EXITING check. > > > > If it is called before seccomp_filter_release(), this doesn't really > > differ from the case when it is called before do_exit/exit_signals. > > > > If it is called after seccomp_filter_release(), then is_ancestor() > > must be true. > > > > But perhaps I missed something, I won't insist, up to you. > > You are right, this check isn't required in seccomp_can_sync_threads, but I decided that it is better to be consistent with seccomp_sync_threads. Thanks, Andrei