From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796293888; b=sNY0NyxhkKBQjHzMi1nMOL9IbFHFgnOE0XuWUKTmfh3E4L/8l8ksITu6PCi+nmChJERr IZ6MKNvsAeJ607zXinMIoiJ+Pj1ED0SR/1RBMDYRGK3Ol+vO/RsLiFyMIDIquR+QH/age wdfZbuxHpvodDTovP37dmQvmAHe7qZwLsaTknJjMXtu2Ou4Pd8ZZyKUPMxPh3GLyxH7iW spnq3gw24v+1IdQpxlTTA/XF88Bj19i5p+Us4/9lxKkkQvuQBanL3YrSDIgv9v4BE1QGe A+K8wEXR6Ab7gBF3bW4r6czXCs2Nfflf6xUeWU84iDxF3s/f44WT3TQEPxSRHQwyRuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796293888; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=SlsmHcR4LuMzCx4iYhuWwuWPF30m2oVXxzQAT+vNa+0=; b=3xLZZlOuasb5PHr38/ANYDZSCSGMl+Sb08a4U/otu5+XCU5X8znkbG2r1xMjn0govzJt V8ZRkaUc4ANzz/Ev5itj57fkrvFESUv5qpcN5/YLwaILBurJNTFQd8nmo+rL4/Xkuiw1f XtfRmvz6c8BouRtN0zsw3GGTP6y7nkexKP7REvtK0Rq2MV5UNULTY+d0KNxC7MJ7BF+37 mOjcxqWC1N5sOE2BjiyuqeJVFEWzPFzr6bl+XTDAR5rSZkacAHMfanUG9312EKLy9vtE5 tFCaNpJuoub4xaUKUJXLAA/Kz00dR77/hN8GffyxllwaO0s1L5o0Q8uruxrfV1Dr4HQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=04qVEuHP; arc=none smtp.remote-ip=209.85.128.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 19E8F606A32F for ; Thu, 3 Dec 2026 10:31:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 19E8F606A32F 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.a=rsa-sha256 header.s=20260707 header.b=04qVEuHP Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4bb6adaf0f1so116885595e9.0 for ; Thu, 03 Dec 2026 02:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796293886; x=1796898686; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=SlsmHcR4LuMzCx4iYhuWwuWPF30m2oVXxzQAT+vNa+0=; b=04qVEuHPwQCjgQJvH+rpsO+mOHf9/9I31Swx1wU20nO8jzVbq+ITiEXS/E4VcV1En9 +Q7J0b4pp5tan9fRAXQNtpt5t3Bwi7d96OP251V3vs4uxvv/VqGL8OZncI5veD9J80Vy nt8wGUdqqoXh2f5Hd2kYcVxoQiznjgz30sIYDqAfOU4Utf3lwjcMrnLyx3y6unabXpdY OP8BoJqX9eTNjNmFzN70JcK7wSyrADnxX5fKMI9YpP876euXzX/yLN8t/oJTJtBHhQn3 EXyUy6nlmQ1tLRijagMlmXZl/nqzL+bo9KyCPeCFU6qU6foz9IdzVdZzo6UcV/p3y5pN q2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796293886; x=1796898686; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SlsmHcR4LuMzCx4iYhuWwuWPF30m2oVXxzQAT+vNa+0=; b=jk568qWM/AcXt2q8egv14hi7udVmKYLTR5u+qufhtRRBnrU2KvSFw5N/XTwRjVLnll 3MIdDYwFQj2OrQQJV/0cUH/eqbdkxLLgZX9eFsFYTsezdWMwFtWeFC4iZcwfl3H1p69x Ut5vV46a+SqCajzzsmHkuxNhMXbCbfVFkXktj7RZBOuXS874Xzk0sUFFw8Z5EPYXvJIa ZkEMeCzABqYYD6TKyCEOEU+2LQLZADqkonuAbBWsm9lt3MQYVgAfTl0aMzzHouI+RTEq rVbEQwwdAfQ543YBEEa0rnL2JEfC8+zH7DytG8HRG17XijqFImLBsZSOZejjHGH4W8RH wtlw== X-Forwarded-Encrypted: i=1; AL+hErHBI3d2nnBDZ71iyVeaB1+krbZ8pix/MprErn/VQ8IxWktDZGibVajhqOCzsBwHxzSVals82uDT19i47xywZ648F48bOtU=@vger.kernel.org X-Gm-Message-State: APuU4Z9UilEU0cRofz7cm4/fkcVQuNrY7uj6xzWOTKhFeY3MZLojLvvL T3hLSjuxH3AUZT2WGaiA8Dfmw1bSC9sSZfdIqHFe6tKZJDXE+JpBP/ZJ X-Gm-Gg: AZFdTZdetiCCA8mwcJIkf+4004R3F0tNdbxKretliDC9JkNZaJ6W8eRcyfnktTqQCr5 V/x+kh2ab0eSYlhVr2M+dt9EZO6FVEXZjATlXMpuV7Wk3VLKb7Xuh53tulcPtuMf6P5XvvxDtY6 f+jM2QxaxTisl1unmie24+cfo/y24iu+OsYxWuPhstXYsB7NiljjMkq4K+JaMq87CxT1qTMIqL4 c36raR1S4hYafEiIevWl/8pPx7lqCAu/735FUoazEDCqmwYNbmrAhJ/63cZoaTLSSwyPBz+614q PlocojYAkggEnkP/vIfEq9gRJ/Cj060eKwASaJ7Vb03EeDNElL2SfgZRBvsdfDnodaPf4mPRGX/ dLOlZ2uj9dYL5Bq9FWQTz/eD35EMuktdYjYfKWaKTEsUUZBP5cA5y/N1ZakFsZaD0Xv2KeqZ1Rk wJxtoMjYyLW0RhNVlbfXTnUiivS7ktDwrSw+39LcjFERbz87Xpr5BPNUjAFTLflWmyD602NsdgV kFIiNKoX4A6W36bWc8XUcCm3WUKHbrGIg0GcabcrngAzam8eHcWFGBG80zk+8MavIOSLrpLTo8J vjeBmzM+Yf5+joGiZZTSa97fCp+7E9dFTKXtwtoJze1QDzQyND6sT9wryPxv5W6V8QhISg== X-Received: by 2002:a05:600c:46d3:b0:4bb:5c92:ce12 with SMTP id 5b1f17b1804b1-4bb88812200mr924684205e9.17.1796293886220; Thu, 03 Dec 2026 02:31:26 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe005f4bdsm58924375e9.9.2026.12.03.02.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 02:31:25 -0800 (PST) From: Anton Protopopov To: Miklos Szeredi , Amir Goldstein Cc: Anton Protopopov , Christian Brauner , Paul Moore , Stephen Smalley , Vivek Goyal , linux-unionfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ovl: put the copy-up credentials when the copy_up hook fails Date: Thu, 3 Dec 2026 10:42:43 +0000 Message-ID: <20261203104244.1015716-1-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Transfer-Encoding: 8bit The security_inode_copy_up() function calls the inode_copy_up hook of every LSM in turn and stops at the first error. SELinux and Smack allocate new credentials with prepare_creds() and return them in *new. If an LSM which runs after them fails the hook, for example a BPF LSM program which denies the copy-up, ovl_prepare_copy_up_creds() returns the error and the credentials leak. Nobody puts them: the cleanup of the copy_up_creds class skips error pointers. Put the credentials before returning the error. put_cred() accepts NULL, so this is also right when no LSM allocated them. Fixes: d8ad8b496184 ("security, overlayfs: provide copy up security hook for unioned files") Signed-off-by: Anton Protopopov --- fs/overlayfs/copy_up.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index c147ad155b79..6195e5d47174 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -732,8 +732,10 @@ static const struct cred *ovl_prepare_copy_up_creds(struct dentry *dentry) int err; err = security_inode_copy_up(dentry, ©_up_cred); - if (err < 0) + if (err < 0) { + put_cred(copy_up_cred); return ERR_PTR(err); + } if (!copy_up_cred) return NULL; base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb