From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795723262; b=vqYYdvwgnFWykqgSYwRhsSkw2aje+2XL9PTqhBFz4y36kI58OeYkHiYtWX9pw/8+Rfki u5P6ZzIzWLSULYrH0LJhdCGyDq7ryuHCookM55hcJbJM5PlIozcZ8ll0NF8djbFUgsas1 Xku4wvhi3o8FkkjDiTilfbMCQA+7RInfsBQApQH3c7eZAG4WiF+XOUmRfVv6/phOtvILs WBbxBqybrt0OKcF063doV1HeUl+5C6z6Px2m9HRqAmpt1tXlpG+iAXQ/dKjN3zB9gI3dc yu20KnMmxhjLTfKIwB4X493dxv9BVrljCRJWqfrtEDl9DChAL1KDRaqVAa/KirVktWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795723262; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=6kyFcKzeGDxm7QHLL2jhZm3kVHS8REfuYCj505/rh+w=; b=KAauev+pVUgvM999dB/44syC8aYNcSZblFnweYpOQ4hQkCtyCzERADM7LRzwCvm80+eo J0+nET2Wmuzt/d4cjgT3D2lxeoCly9iwco2fsScMeCjkUVz0i8Yis13YfWiorA0A9P51U dFIawkTLLP5sGjJ1iXYKQMD7N3tNEgHzh9Wu90LLk/QZ2JKZJCgIweq6jtsqH9mHJIpn0 NS7RBTaNlrSMxg+5E/N155Su0ogaglZOI0tlNqfw83B4skBvYyUMXBpI5x10hH64OrSRa 4fVfV7r4LK1C1fWHUM+lJtX/WbV+jo1I7JNeuFnTGYpzsnjG+pLkuJ23tf7JU5vRzhA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DWn5Adbn; arc=none smtp.remote-ip=209.85.167.198 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1950606A31E for ; Thu, 26 Nov 2026 20:01:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1950606A31E 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=flex--zhenwenliang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DWn5Adbn Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-4ea2c058e67so7812529b6e.1 for ; Thu, 26 Nov 2026 12:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795723260; x=1796328060; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6kyFcKzeGDxm7QHLL2jhZm3kVHS8REfuYCj505/rh+w=; b=DWn5Adbn/TnNY1xH6jgc26TeZjfcHBww+a2kKpHR/5eZOfNI4t4Z8aZ+omqwN2qsgm yCCY+enUXphkASUrR2TQTtRUsbfdpo/dOnwNQidEPIzUBdvoLll/U7bOMSQrkFBhmlgC LFdps5bXzAbXF8KyZGclTM8zxvQawERuH7hjUYr8k8TiLMccakam0RxJTH5Ras1LDvAU tqiDFp4hF8T13krvROhq/XaDdR0fXEqWiqmsuLW5RV0vKZWaPH9gnzcEwwXLg0rLFctj ZGkqJQtLYChkZZAgCZjAT1GFaA/XkgDu+1xVJ/ICK7iYXkodppDvgxd5LykFlB9tdHlW VOkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795723260; x=1796328060; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6kyFcKzeGDxm7QHLL2jhZm3kVHS8REfuYCj505/rh+w=; b=qbV00S9JuwakYHCQiGtNAetOq1x2Pwf+SAx5M2zYGmZwqQQalMhvU2JduWsQY9nlCo P5mQjRPUiL1gyakDh9+GC9cktooCas8tibjC7UtwzZZO1C/kzUsQem5HSw5yh3q16JhF EEVEuL1V8wK24zvfthLL3/9p2BTqyu7Fe8b03aLwXRmFPWexaiD9ORnOUsCeE0FV51sx zOkxxEC6rQZoSQYheNSjRYYi01ecZv4m1yO6EyCzvSHkvwzfqHAWKTj0je0AZ3EaecaA /1LsbBoi/Cm3XWvfnec2l98kEqfkjymkgr9y/WXabo5iFZ1aYJT8kLcSIW0/Aos0AauU QhXA== X-Forwarded-Encrypted: i=1; AL+hErG27Wxzk2trauKQ+c4zxvRG7+3FXdHRnMyrDv9hwU9I3so8T8J7dap7ogVeqd9zcFHJXRK+k7nHSoiFHpOnADuLhVl3uNk=@vger.kernel.org X-Gm-Message-State: APuU4Z8Eku+zo6pHVhDgWoDH+/faNGylV9zHfBmZFsJT3/XRwAU3FnAk tTLdjA5mNRshzmA+RB3oa7JMcdZfG5yexrd0PLZ3Gm7CBirXVkC8SdnVznLfTlx/7PkJq7RGw06 LTn+WdsIVpf5/HXuIv3hKXsNxxoJyvg== X-Received: from ilbdv4-n1.prod.google.com ([2002:a05:6e02:4004:10b0:53b:d747:38b5]) (user=zhenwenliang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:4fe7:b0:4f6:5279:5c75 with SMTP id 5614622812f47-57a0a50337emr26068171b6e.28.1795723260332; Thu, 26 Nov 2026 12:01:00 -0800 (PST) Date: Thu, 26 Nov 2026 20:00:58 +0000 In-Reply-To: X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261126200058.2806412-1-zhenwenliang@google.com> Subject: Re: KEYS: encrypted: encrypted_rcu_free() callbacks can outlive the module From: Zhenwen Liang To: Jarkko Sakkinen Cc: Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Thu, Nov 26, 2026 at 09:07:15PM +0200, Jarkko Sakkinen wrote: > This will be ultimately addressed by: [...] > As then operations will be always drained. > > It's actually somewhat tedious to address this particular issue > without this type of architectural change but I'm open for fixes. Thanks. For trees that will not get the series, I think a minimal fix is possible here, because unregister_key_type() already guarantees that no new ->update() can run once it returns: key_create_or_update() holds key_types_sem across __key_update(), key_update() checks key->type->update under key->sem, and the dead-type GC pass retypes each remaining key to key_type_dead under key->sem before unregister_key_type() returns. So every encrypted_rcu_free() has been queued by then, and an rcu_barrier() after unregister_key_type() in cleanup_encrypted() waits for all of them. trusted.ko has the same pattern (trusted_update() uses call_rcu(), and none of the exit paths waits for pending callbacks), so cleanup_trusted() needs the same. I reproduced it in QEMU with KASAN and CONFIG_RCU_LAZY=y: add an encrypted key, update it 20 times, and unload the module right away. The rcuop kthread hit int3 at encrypted_rcu_free+0x1 in the freed module text in 5 of 5 runs. With the barrier, 5 of 5 runs were clean. With your series applied, the barrier is still needed as far as I can see: the GC calls synchronize_rcu() before the module_put() in key_gc_unused_keys(), and key_gc_flush() is only used by dns_resolver, NFS idmap, the SMB client and rxrpc. On top of the series, the barrier could become a key_gc_flush() call. I will send two small patches (encrypted, trusted) with Fixes: tags and Cc: stable; feel free to drop the stable tag if you think it is not worth it. Thanks, Zhenwen Liang