From patchwork Tue Feb 6 10:16:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 197307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1449483dyb; Tue, 6 Feb 2024 02:38:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCdXVvpu76Cx5yuz8OLNSxPKyvxjS7sxRYAkZqTUzIhe3yxzZ/Q0ozrDXPa9Uf2ga2ewhi X-Received: by 2002:a05:6870:b48b:b0:219:2634:11ee with SMTP id y11-20020a056870b48b00b00219263411eemr2591824oap.48.1707215896182; Tue, 06 Feb 2024 02:38:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707215896; cv=pass; d=google.com; s=arc-20160816; b=VLmdL4lzJjLDsIAPVhDGTDjrXJHRUvYjMuOC1a+EMj13uNQx8yCm6mXLRrJsGqGMSl F2qSlM0ExfQA8ZfPveCwvi+nStm8PTPaTHM0z2Hw/QQyo0ZLMD3pp2QmJUO+dm3YenOX DB2sEwMphq752zrWf2UqoamOn93YpY3VR3HOMa6k6MvyjW56P+d858p/Pynr+oamM389 k8rSwPUjMJ+npxXP98k2vwxxAs2cRq9L1+Am37NtrzJLppqCRrNXx9qWliF0jBVIBuCd ovR/D8aFIixbiUimumOSgQj5agOgu0GS6J5Sud8XgwW1tCC3bOHILcfgb6aKand7BTMB ydyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=Qjjytxk+YrJqkh2UdaOiVqqhU2xaLDtEuunmNkVgd3w=; fh=J1F9zEe0IARskJEc7fXv6Qq5lOMjguR4skw6WDgCI7I=; b=ib4FsHxqf6mfUtpetiwCi2psMVzEP68WCKM3J3mpwm1vSuwG/FJFRqa7NPkcLKE07s oQw/SZramllax6/t9zQeMCT68gmWxqWXwkGjFy913lj9Mw4rjkmtOb1lHafDZdsgknIO uGA3C8GFtxp2LzNox1UfyeSAW2UULe5XIJgqDXKOk7nFu00M7OhbASqgzpiAluvFGUUb zXlddFPjjcKQNorzTXx05EH9EkFbYXGdWvLRxZr8n0IHOl7nHiExDgXHdLN5q7fpDiEg KsyN+CMQK9zC+Y9JqPVk1AqDQVun4wBlbEp+1VipCKH0zTY8d4pFp31J6SLl8ZGjNTjJ 2c7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NjtyuZCZ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NjtyuZCZ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-54673-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54673-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=1; AJvYcCW2Gyk8t8RErNWAqJFh87hS7bSNtY+yehH0/P4IAA5x0zigVlPW0E/JsV+BJn++p8fgYr0/UxP5+Ums9OawNMeMmX02Tg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f11-20020a63754b000000b005dbcf612461si1462423pgn.416.2024.02.06.02.38.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 02:38:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54673-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NjtyuZCZ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NjtyuZCZ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-54673-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54673-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1E8E328AB8B for ; Tue, 6 Feb 2024 10:16:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E508712EBD3; Tue, 6 Feb 2024 10:16:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="NjtyuZCZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Q3zU5kg6"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="NjtyuZCZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Q3zU5kg6" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 73F6C12E1D8; Tue, 6 Feb 2024 10:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707214586; cv=none; b=c4aS6sXOoo8h0WezV4ueFwF+vZlM7/9FpsQRG8MDZpWjBdGIeLV6Uf17WvsY/ursU7Klwy/8XmUkfbGe1DiOJzlELEzNxnsqBBArJvkjSUn59iyNuyb13OJyeA/KE/5Sv5pvAAJWoCfYMsiDVOWenGQwUckOdWHaky00exwhsiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707214586; c=relaxed/simple; bh=JLStoQUTBclwGMIg4iQAeZltWYDX8/fp91Ubem0/TXk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VzoAfXvAzMZsqKc2Rqe4QuJlyjlDozga9tKudR3hhnF9RcMZT+VbIwAsYzFFUU9Vzl0AzR3maGw1KnDgwsFwKPbbgIV4RFj5fGoAyGc9+cif+hiebqrRYSTBeHvap38+K/jqYAxdU+GYbSz83TrsdQWcFG+iEpTqELIm3wkQH0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=NjtyuZCZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Q3zU5kg6; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=NjtyuZCZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Q3zU5kg6; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 142CD220F1; Tue, 6 Feb 2024 10:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707214582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Qjjytxk+YrJqkh2UdaOiVqqhU2xaLDtEuunmNkVgd3w=; b=NjtyuZCZvpGOxb1zkmajaqwpdzbn+CM8/0dcTsqDHkcvnRAjzN5L2PBBgyrR8ai0fmuuh4 LCOVS7mBETFu6G39tUgwUOCxYxefpw7NRRS3nY4nPJaxWSk3PR+10cSth+iaVQxLFTzLIp Vf4sI2gJi+ekoqUCXIa3X6luvwCq+0E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707214582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Qjjytxk+YrJqkh2UdaOiVqqhU2xaLDtEuunmNkVgd3w=; b=Q3zU5kg6tfmOWkjaMA7gF4JDyIBYWAglfBv36DQ3rx3uL0ZaLsWBI8ACL/DaFRriH/1obI sM0Tb0jcAcHpiyBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707214582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Qjjytxk+YrJqkh2UdaOiVqqhU2xaLDtEuunmNkVgd3w=; b=NjtyuZCZvpGOxb1zkmajaqwpdzbn+CM8/0dcTsqDHkcvnRAjzN5L2PBBgyrR8ai0fmuuh4 LCOVS7mBETFu6G39tUgwUOCxYxefpw7NRRS3nY4nPJaxWSk3PR+10cSth+iaVQxLFTzLIp Vf4sI2gJi+ekoqUCXIa3X6luvwCq+0E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707214582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Qjjytxk+YrJqkh2UdaOiVqqhU2xaLDtEuunmNkVgd3w=; b=Q3zU5kg6tfmOWkjaMA7gF4JDyIBYWAglfBv36DQ3rx3uL0ZaLsWBI8ACL/DaFRriH/1obI sM0Tb0jcAcHpiyBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7771913A3A; Tue, 6 Feb 2024 10:16:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id xuDNGfUGwmXLfAAAD6G6ig (envelope-from ); Tue, 06 Feb 2024 10:16:21 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id f760fa64; Tue, 6 Feb 2024 10:16:20 +0000 (UTC) From: Luis Henriques To: Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim Cc: David Howells , Jarkko Sakkinen , linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Henriques Subject: [PATCH] fscrypt: clear keyring before calling key_put() Date: Tue, 6 Feb 2024 10:16:19 +0000 Message-ID: <20240206101619.8083-1-lhenriques@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: *** X-Spam-Score: 3.70 X-Spamd-Result: default: False [3.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; BAYES_HAM(-0.00)[32.10%] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790145615689004882 X-GMAIL-MSGID: 1790145615689004882 Now that the key quotas are handled immediately on key_put() instead of being postponed to the key management garbage collection worker, a call to keyring_clear() is all that is required in fscrypt_put_master_key() so that the keyring clean-up is also done synchronously. This patch should fix the fstest generic/581 flakiness. Signed-off-by: Luis Henriques --- Hi! I know that patch "keys: update key quotas in key_put()" isn't yet merged but since David and Jarkko seem to be OK with it, it doesn't hurt to send this follow-up patch immediately. Cheers, diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c index 0edf0b58daa7..dfdaae16b83a 100644 --- a/fs/crypto/keyring.c +++ b/fs/crypto/keyring.c @@ -74,8 +74,11 @@ void fscrypt_put_master_key(struct fscrypt_master_key *mk) * that concurrent keyring lookups can no longer find it. */ WARN_ON_ONCE(refcount_read(&mk->mk_active_refs) != 0); - key_put(mk->mk_users); - mk->mk_users = NULL; + if (mk->mk_users) { + keyring_clear(mk->mk_users); + key_put(mk->mk_users); + mk->mk_users = NULL; + } call_rcu(&mk->mk_rcu_head, fscrypt_free_master_key); }