From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (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 2FD4835EDD0 for ; Tue, 13 Jan 2026 19:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.66 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768333471; cv=none; b=IUwtJfWYCn2BBQra4E73+LQnMghWYbDOFT0jDUTvbBDpLvXrJPJgf600sHHTPSFzSvTDnDtnOZoDhfSRTvzAKMfYniMIp/ElsBmNpnTcF7MAZncVNbd0nlazWvFtx38g2TVRO2D95+8NztWwr1xecJT83N5OpLnkzZUECnb1GK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768333471; c=relaxed/simple; bh=+5eNlG53pCnP2H6HkD8AFxk5fYZZbrZGswP+g2LyVEA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hVWW7ogIXtr2wu7ZoGMQ9lsdBudr6stpBucVJhR99cN/UM4TrDCAOa5VT+qpyp67gLF79bLR12EdXYW+Sf2gOZw3/NP8ELLNp/2At6jdnLx9QUs99rYBAgzgGsyDBkH1qonH5bxH0Dxxgi9oWro6l8Xml7LO3rM7V1tcjyhlj0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IIVkepfR; arc=none smtp.client-ip=209.85.128.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IIVkepfR" Received: by mail-wm1-f66.google.com with SMTP id 5b1f17b1804b1-47ee2715254so1485105e9.3 for ; Tue, 13 Jan 2026 11:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768333468; x=1768938268; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wzKJiDxWGZWZK58KulJ6Ai7jgCO+I4d2FOxBhj+H/CY=; b=IIVkepfRlSbS7/7rFiS+cOJV8Pt1kpWkQeE/8QvFhKwQgNfcBMAnc+2OHUg5kegxuQ C6I1JRmbHGn2ulDJxFvRTUjelI81AMWAecVT35Lgxh7oz4fzTeQ0pmtXY3ljju4/zLrx JXddVc1GxfgRkyfGKZZ33XrJ+6NcOvE8AURAH1s54jBzO7bcMVnHzgRz/0UA+xZCRd1v R5kkM2SqrPEKquLIatPG0EECBY+ECFaXcNZSNgxq/cCmPWlCHfj0YzQjU0VZjZt5E7CP HOMSfAgLagvjNhhmWmITe8w6wD+YEn32nMPMAxRn+0u2h45h/Zex+q0hM+dWN6gHAPng EIRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768333468; x=1768938268; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wzKJiDxWGZWZK58KulJ6Ai7jgCO+I4d2FOxBhj+H/CY=; b=v77YJqWRKr4yZZ1EiCSEUvVNez85sNZXOOfR5PekMEmq4vERl1cctafw3aeVQ7M/RP rUoee+ChJGzVtWnlXD04fy/ELYuuxPnhd9YRa30w3fyJh8riRCAfTs5lc/8I4cBiCQdi Q0WqU6nLosf+qgv8G5aaqdtPHcDpAjQNZeac7LAw7Jw0RAJcyYWHPkycB1DxDM7+8JYM zhZLxV7TQlJfnCZ/4u1d19EvRXJ9d9+To97cWJrLRdhw76IN46Wlr/4r8sqmjRN5A12E LEPOJZClZDmvVDxWJ5AOnZdDHotKoCm/58we6wBzY3jlPBS4oiYTSMpGyRxm/gnz4aXF sgtQ== X-Forwarded-Encrypted: i=1; AJvYcCWsWXQe5E3jo3qdzWG0SiEN3Usj3TW6CClvOyb/uVdZNe27w3sYft43kGQbGLkpqRGuv7oUADcB7pFffS0=@vger.kernel.org X-Gm-Message-State: AOJu0YxWExziv+Ih93NhCj7tALSUdRZOcRd9uZUFHZvRXnyrtrHjaHX2 STibTmTFWgM0rgNseZFTQcF6a7FB28tN8yXoqmUBXIORZ82n4Cs5MMMl X-Gm-Gg: AY/fxX6HQBfM006bFV9+kTx5CN+OTnQ5IyAgqyTuu3MSYvy1H2cf5wzGFtLFC5pCGYT CYK37IYDgjkpjff9EUDU+1e9PHarDx/EBO0xXHcia7CdCBtc3O/vkI8r0+RXYdCw48y+xlB2OAh /lMd1DLCtsMcGE8qYwiieKobC50bYtgqxnHngi9YKik0O8tqhA6KdMB7jvt3cf22nVVwWyHbr55 49JPOdll/drWmJObT2h5QHkRuwMZyGklQ25Wu3+Ejr99EW5YLFvpYkHfWzMIqg6I+U+MXcCNmHC jQaz7Rb3o1qOZy995p+Y3STgLPeVy4IMzxJnEp8qraUKPBAtrk1TLgFhii5Xg8jdba0aGvhs9aR WJxzXOqqY3A/eRM45Uarnp+IDt0qf9FIa9DKiDQQbTNOoJR6WYVTMctqC0SzBD3OHoTImfum1q9 vloXXhIsAsA3Hf+XiAQ2ikUQ9ZmuZ+G0gFmWAS3GgkwJETeDZkgfF826LYAkWExqKHU6hBEkKEC huHVTEj6Qra/i+NFz1Z0+eEX+glHZP2+0+ScXfcmblK4yYPdJrPX+8iId524bMUZg== X-Received: by 2002:a05:600c:3556:b0:477:7f4a:44b0 with SMTP id 5b1f17b1804b1-47ee338ed50mr3080765e9.33.1768333468295; Tue, 13 Jan 2026 11:44:28 -0800 (PST) Received: from ?IPV6:2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c? ([2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432bd5ede7esm47023689f8f.32.2026.01.13.11.44.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Jan 2026 11:44:27 -0800 (PST) Message-ID: Date: Tue, 13 Jan 2026 19:44:22 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] io_uring/rsrc: fix RLIMIT_MEMLOCK bypass via compound page accounting To: Yuhao Jiang , Jens Axboe Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <20251218025947.36115-1-danisjiang@gmail.com> Content-Language: en-US From: Pavel Begunkov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/9/26 03:02, Yuhao Jiang wrote: > Hi Jens, Pavel, and all, > > Just a gentle follow-up on this patch below. > Please let me know if there are any concerns or if changes are needed. I'm pretty this will break with buffer sharing / cloning. I'd be tempted to remove all this cross buffer accounting logic and overestimate it, the current accounting is not sane. Otherwise, it'll likely need some proxy object shared b/w buffers or some other overly overcomplicated solution. > Thanks for your time. > > Best regards, > Yuhao Jiang > > On Wed, Dec 17, 2025 at 9:00 PM Yuhao Jiang wrote: >> >> When multiple registered buffers share the same compound page, only the >> first buffer accounts for the memory via io_buffer_account_pin(). The >> subsequent buffers skip accounting since headpage_already_acct() returns >> true. >> >> When the first buffer is unregistered, the accounting is decremented, >> but the compound page remains pinned by the remaining buffers. This >> creates a state where pinned memory is not properly accounted against >> RLIMIT_MEMLOCK. >> >> On systems with HugeTLB pages pre-allocated, an unprivileged user can >> exploit this to pin memory beyond RLIMIT_MEMLOCK by cycling buffer >> registrations. The bypass amount is proportional to the number of >> available huge pages, potentially allowing gigabytes of memory to be >> pinned while the kernel accounting shows near-zero. >> >> Fix this by recalculating the actual pages to unaccount when unmapping >> a buffer. For regular pages, always unaccount. For compound pages, only >> unaccount if no other registered buffer references the same compound >> page. This ensures the accounting persists until the last buffer >> referencing the compound page is released. >> >> Reported-by: Yuhao Jiang >> Fixes: 57bebf807e2a ("io_uring/rsrc: optimise registered huge pages") That's not the right commit, the accounting is ancient, should get blamed somewhere around first commits that added registered buffers. -- Pavel Begunkov