From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796228147; b=HVVHS6fvEsKM+NX99csXYRNyoANed0Ou0JLZ8lj5Iwb7PfNFyn3Tde+dOkYT256Cyrkv HLGFY4e38akjKAkgCb2uD/Py9FWjh1jy4cEL1/JEnIpcJ+ivR0es5R+l5n/rXEzExlHot FzfWkRWl2iM7Wp9Ch6Jsn7iDEwkVbtpzbE+2FW3GCZ9DbMnpaKVz3rgbetq/EEyuH2s4n jj6T2ztJZFAemg8YUoZtHLSNtX0+RI5DHf/zXnBSNesYiXQSGfVWajF0mE0y99h6gQMy+ AEoEOfit/sT8skhxKNTI9MqPG5YOID47IMii9qR4eM1uhWwSOvHIarVc0tuRDh7oPMw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796228147; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:From:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=DA/CxwgIMYdB2gcClV8DF59dKtA6jbI67hyQB6fMIqA=; b=c1WTemfi0x5JelHITh3vy2j6TgHulfOJorm4VKImOLcEE0FTOm2WXXM6euaZF9JZt7HD RbH/zPIg7RJLphjng6yCfBEHdsnnnr0ddUrRCoTTdzirYogzLoggoBI7nLa7xw0xS31Lw UOzZZ7zBW0yVJ4K24Qw+IXfN3U42oxIigyn+z34XyzkK297a6CEb0TOxuSRAQurI/QF7E 2z09MRCwwrFWs+8/6ARb1cMV0i4noGJWNbCSc43M+/G1Xlln27pL4c5h4vnWObaiy3YUN E0JlwVU2UXzEK3wteZ+nBNy6CTR3nMYgBiWepAaTMFBb1TgvbWN+hz9ohNuQcEzvH5g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=Qpt+YApz; arc=none smtp.remote-ip=209.85.221.44 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 276EF606A32C for ; Wed, 2 Dec 2026 16:15:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 276EF606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=Qpt+YApz Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-48e20ed3b9dso11876248f8f.2 for ; Wed, 02 Dec 2026 08:15:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1796228145; x=1796832945; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=DA/CxwgIMYdB2gcClV8DF59dKtA6jbI67hyQB6fMIqA=; b=Qpt+YApz2wQE19WGrtlmh6fUlHd27ZVTBG4Erm3rdaAty7KqL3sQayoqRIJ8PlZUko vJhbaYY/Yjj7lFbk9lFsz0W3V8Ryg/uzW0IszqkTrOhJccipGYwbEEm0OTlxcfjDyuD8 98PMJdvTMTLO9i7+deliwjykntRlxyhQTKyTuMA4gsvXLKDhwi99+ouwo2ulidlVCySi t3GEgIiMylARFNtw/PCrgDfffxdkKUQxCAeGpQtu01TwlczkWnHaOFDsYCjCuAFVnCiG Umcv/5bVVay2k7Col8FrrN4KWTXvK8XCkEu/NZ4w/rW9e1dmk7zrOyb9zTBxyCoGQiYS dqOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796228145; x=1796832945; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DA/CxwgIMYdB2gcClV8DF59dKtA6jbI67hyQB6fMIqA=; b=gPyZu/0KFrd/SwhjIcXZoPUmgld71MBscSNWpxV7gRYT9CIB++AicLLTwkedtZkQq+ ljBMJF1je9D2HhcoZZgDtKwWIxehtJx2K2JWevtFt3YCAMqy4eoov+nTbQRjv241yu1I qjSaLuq1NtI1Udx3+j4vuZ1JeeXKcs2XxigXAmcWCayaE+LVi/hDxyqq5tljWmjLfD2t K9UO4Vz03hZMHQvEmOzfbuUUV6y+uhjwQXXhBTGSBr3egN55FvWkAfPIqz9b0YOYMcpZ FPLM/lo0PqlTKpO+4Q2czFyKIcl5KFBeggQl5g1+zfnbqNRSVgJ4qsLzqH48/dhwYv/Q ryKQ== X-Forwarded-Encrypted: i=1; AL+hErEi11T1OSCma5cF4QK58RMoear1xChjkxgmQY5BFYA3dCuzMPpSUm4+ZAE8RFRj3oPVZQQqEd0kIpm1XKI=@vger.kernel.org X-Gm-Message-State: APuU4Z/fRCMZ6UEnH2w32UIF7kqm9q4I2J5oI5OAuh8jD4HypuIcsm1m EI5WLUzJx6Je8n6qPW+S7frbTUYCW+/ZAyEpckRtoat6AMqY1fUAZy19ujNnaG/Y8qDzzsDxCXi JgG5ySjk= X-Gm-Gg: AZFdTZeMOpIMukiHishxfL6x9t37mTI4qREKYe1geqqhDx4WvhQoVxGSlyDdgxEl4eX xYx9s5Xrk54H/xZuwcB1a5RHdHzGhAVQjtipj19gI+8FkTH2902nqeWOKcuacLdfuGZCcJ4PgE1 hX1b7J6F+tYy7MkxKZGk+JmLRdAwSo+KxxbDeIHuK5PB2uTvyBCfNhTpS7lgHbX92rkUwf5171x LmubDSF0Xnev/W/s7VoiHgDpvWkUkhVQUXzMH5N1NorD1LtGmBDoJSKr6PVMC/zs1d0MihPbaII jQcZOMKuy3UgYmr/tPN+8hdfXnP3zwOR7ZRrwMISaROSsHe0WG7SnTqq2FG6nBgkUyLdAlQpZtW lhLde8iJmrLndhwQHlG5F9dUBNB8w4JpZTS6FBkl8jQbXfF5GIsw0LPBHhWNNfsk9vOJLdx4BWc lN4oTh7moTjQ6hNLVMya5oz7z5WdxjNgwYeDCRSPg4D7mDEp+fbp6fqQRYj3R7tNqi/3ENcYxlJ QWyEsi54UBv8Ut9+CxyqiEmTXEUCcMNPXfVcMB/0byztjf7DSfpAbj8d0xZX/gVnZVAbl45ZelJ E3v2SDtgBNVCenxcFF98ViSUD6b+P9CBKU/vZghoK6Tg5hLpOc9MtmWQYWgMW4iN X-Received: by 2002:a5d:4492:0:b0:4a8:1b63:215d with SMTP id ffacd0b85a97d-4abb6eed6e7mr59653193f8f.27.1796228145542; Wed, 02 Dec 2026 08:15:45 -0800 (PST) Received: from ?IPV6:2a07:de40:8100:0:89a9:fd0e:583d:4a53? ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b10b5f6sm73292561f8f.34.2026.12.02.08.15.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 08:15:45 -0800 (PST) Message-ID: Date: Wed, 2 Dec 2026 17:15:44 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] module: Fix use-after-free in module_put() tracepoint From: Petr Pavlu To: Aaron Tomlin Cc: mcgrof@kernel.org, da.gomez@kernel.org, samitolvanen@google.com, da.anzani@gmail.com, linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261022184517.66438-1-atomlin@atomlin.com> <2fd1031c-7a86-45cc-a595-bbd13e102d43@suse.com> Content-Language: en-US In-Reply-To: <2fd1031c-7a86-45cc-a595-bbd13e102d43@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/9/26 2:47 PM, Petr Pavlu wrote: > On 10/22/26 8:45 PM, Aaron Tomlin wrote: >> A use-after-free condition can arise in module_put() should a thread be >> preempted immediately after decrementing the module's reference count >> while the module is concurrently being unloaded. >> >> In module_put(), the module's reference count is decremented via >> atomic_dec_if_positive() before the module pointer is passed to >> trace_module_put(). Consider a scenario where CPU 0 decrements the >> reference count without reaching the baseline MODULE_REF_BASE level and >> is immediately preempted: it relinquishes its reference while still >> retaining a local pointer to the module. If a concurrent CPU 1 >> subsequently drops the final active reference, the module's reference >> count reaches MODULE_REF_BASE. This permits the module unload sequence >> (via delete_module() or the initialisation-failure tear-down path) to >> proceed and invoke free_module(). >> >> Function free_module() invokes synchronize_rcu() and subsequently >> releases the memory backing struct module via free_mod_mem(). Because >> CPU 0 was preempted outside an RCU read-side critical section, >> synchronize_rcu() does not await CPU 0. When CPU 0 eventually resumes >> execution, it passes the dangling module pointer to trace_module_put(), >> which dereferences mod->name and mod->refcnt, culminating in a >> use-after-free. This sequence of events is illustrated below: >> >> CPU 0 CPU 1 >> ----- ----- >> >> module_put(module) >> atomic_dec_if_positive() >> [preempted] >> module_put(module) >> atomic_dec_if_positive() >> // drops final reference >> free_module(module) >> synchronize_rcu() >> free_mod_mem(module) >> trace_module_put(module, ...) >> mod->name >> >> Resolve this by moving trace_module_put() prior to >> atomic_dec_if_positive(). Because the caller holds an active reference >> to the module at this point, the module structure and its name are >> guaranteed to remain valid throughout the tracepoint invocation without >> requiring preemption disabling or RCU synchronisation. >> >> Fixes: cb0b50b813f6 ("module: Remove preempt_disable() from module reference counting.") >> Cc: stable@vger.kernel.org >> Signed-off-by: Aaron Tomlin > > This version #2 looks ok to me. I plan to pick it up on the modules > tree. I've queued the patch on modules-next. -- Thanks, Petr