From nobody Sun Feb 8 02:56:19 2026 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (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 65A4F304BB7 for ; Sun, 21 Dec 2025 18:01:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766340101; cv=none; b=PrmiW17KxoCDhi6u62k8aIp32VqqAnhav7IskJJnF1xM5Z7ISUNJZB78EWh6fWwVb6oH0HpDI+pMmROu4KZUdoOSNh7UkY47Gy4GMGBMD5Hkekwdvy2h1nYFq6WpQbHKDQXtysYyV7ErJiSJeYYq4UWSZMDr2EnMIi2mYbtFSpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766340101; c=relaxed/simple; bh=p23rTPaXB4iLA7mrqVNTAV0jfWyH932i0ckS/IM7+KU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M5AGPyCw6G5Nn46WEQYBidmKKi7Pn5htcPv/Sh0UuxxNPN2xRelQz8TUxST/H5aaJIGQZ4WbQ2TLCOzVYvC2hcohts5Ny9fkN1mzEh+dMJsjgO5gyY5nER4PxOZPDaETcVapootn3zlLcf2p5askM0a64VVXVzjQcuYtohwzDxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=e566HlGA; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="e566HlGA" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-450c6f5ff81so1980916b6e.0 for ; Sun, 21 Dec 2025 10:01:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1766340098; x=1766944898; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TMI4gJV+EmQW/dsAUXEtdv+529j/oGL1MY5pHnG4y5I=; b=e566HlGAqrYzNvk52bmuPebS4kNrgZyG6O2EqdISjvJ9oIMZ6xtpz6c4OzJ6hUbyIv 6qSYD3QzJbaNzkexOAViVgu5iX/E7z/cu4YavvEOsRCfai7sx426gqRWuPDFo3gD1CrP pON2RzJJ3EvCWFlIvgaGMHgj9eCoS2O42VQToyHe429oCnteKNV9X7HZCJSwajhLDNnR jYlW302UW8uavwF8EpqAbNEiFuatl9pblgOdpSXPOOTHAjhN+niYa/5B1fdWCeL0O6iq FS+dlG4DwE8eWUm8fP+LGDDbz5dP1HD8Sv7HF4LXzSmDUPJQAQUwALDlKZFYg34terdW 0qBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766340098; x=1766944898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TMI4gJV+EmQW/dsAUXEtdv+529j/oGL1MY5pHnG4y5I=; b=ktVEYy9RLj3e8Avg5GZMnj+ZBS6WL6/vJa+a4z4GlkFNQQlpQLiBUKLX3TEgUpwtG3 NHE4pOuxnyOiOXd5XQxjvJtRR1dUItj8m9l6zCFyTupaiLFwjpwYhWE9NW11F4cGYfT9 x05CLGIFiv3nSMcOetEcOY2oB/0WVQIc889kKOeDkSEoczceM7xV/cANyCGcFztiRUVR eRnOElxeL5wShpQ6XdXpe5SNjwlvc9662Bn3x6A8ryXf3xxKtLHCgXqyDiw6IJKzgX9y vjIQswEgiF1YQanI0CbdjXLXLFwjezjP2nlwPtLLW1Qm1y3VONW8U8YxedT0Ea1rudWN Gnbw== X-Forwarded-Encrypted: i=1; AJvYcCVpXoF+Bos5sKXLl2tOj5mcXAM4cWkI/3YJvNL9i67qGYMmi87r21Ew02CZk/gRm3YaczXyULUBeFlaiyg=@vger.kernel.org X-Gm-Message-State: AOJu0YwBm/g/pNhsk5NvI/lBWdmMySxu2Fv3bfUABP4a8yIw3ai32tNW wZPjYkKh5SeCjZHcMqTyq+z3cf26RMLn01G41qrEEbgyYK1OdbeDiYpj8JVozaiUJAk= X-Gm-Gg: AY/fxX4fONPvLcvJaTv7H68hUsB1pXT29vnxX9xUQiMbs2KVeLLESiQ9QWrp3G5EgqL lpikZcf1BC4LJWfGKY1cCWIFnJ6IRfolFEd26cT9XYVJkFrRkOuF5GjDRIM1gfOuvaN2l3UyKWc P/2aae73fP50J0kPZ4Ll7JzaWfLYduDnkICGydf5zT+NWd88HxPnr5RCdCajF7r3Vvn5C99lW26 rs070PPrXenkSYSQMpstk5R1gnYjq48VoSTF42snJuuxRr4P6UbfOJECwZrlOZJLAWOSXwLq610 i6/hyv4L6YzEy3K7rjiXp3Y8cnMbVu1XTZrhiGCXNN8aRcINPgIPRB/f674xhFVZJ7XA7+jS9Qe Q0QyNQn4MNZTOyPqAaylYqsgbhuiMZ2/VfwdI3cjwA66//7G6jtaCRUnFK0peYlZVoud+fQdZ X-Google-Smtp-Source: AGHT+IFtfgC7EtUhHlm9PN3fh8nc1zUg/yZTdIPC+ThEyW1/WWre3+6c5ZhabM4CkagZUusUsC8L3w== X-Received: by 2002:a05:6808:1382:b0:450:f45e:f4ae with SMTP id 5614622812f47-457a28924ddmr5726915b6e.9.1766340097941; Sun, 21 Dec 2025 10:01:37 -0800 (PST) Received: from 861G6M3.. ([2a09:bac1:76a0:258::281:ed]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-3fdadbf8d97sm4868888fac.1.2025.12.21.10.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Dec 2025 10:01:36 -0800 (PST) From: Chris J Arges To: zohar@linux.ibm.com, roberto.sassu@huawei.com Cc: kernel-team@cloudflare.com, Chris J Arges , Dmitry Kasatkin , Eric Snowberg , Paul Moore , James Morris , "Serge E. Hallyn" , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Kees Cook , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ima: Fix stack-out-of-bounds in is_bprm_creds_for_exec() Date: Sun, 21 Dec 2025 12:01:23 -0600 Message-ID: <20251221180128.1026760-1-carges@cloudflare.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251219195456.912190-1-carges@cloudflare.com> References: <20251219195456.912190-1-carges@cloudflare.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" KASAN reported a stack-out-of-bounds access in ima_appraise_measurement from is_bprm_creds_for_exec: BUG: KASAN: stack-out-of-bounds in ima_appraise_measurement+0x12dc/0x16a0 Read of size 1 at addr ffffc9000160f940 by task sudo/550 The buggy address belongs to stack of task sudo/550 and is located at offset 24 in frame: ima_appraise_measurement+0x0/0x16a0 This frame has 2 objects: [48, 56) 'file' [80, 148) 'hash' This is caused by using container_of on the *file pointer. This offset calculation is what triggers the stack-out-of-bounds error. In order to fix this, pass in a bprm_is_check boolean which can be set depending on how process_measurement is called. If the caller has a linux_binprm pointer and the function is BPRM_CHECK we can determine is_check and set it then. Otherwise set it to false. Fixes: 95b3cdafd7cb7 ("ima: instantiate the bprm_creds_for_exec() hook") Signed-off-by: Chris J Arges --- security/integrity/ima/ima.h | 4 ++-- security/integrity/ima/ima_appraise.c | 15 ++------------- security/integrity/ima/ima_main.c | 18 +++++++++--------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index e3d71d8d56e3..2c9e50c02634 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -441,7 +441,7 @@ int ima_check_blacklist(struct ima_iint_cache *iint, int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *i= int, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, - int xattr_len, const struct modsig *modsig); + int xattr_len, const struct modsig *modsig, bool bprm_is_check); int ima_must_appraise(struct mnt_idmap *idmap, struct inode *inode, int mask, enum ima_hooks func); void ima_update_xattr(struct ima_iint_cache *iint, struct file *file); @@ -466,7 +466,7 @@ static inline int ima_appraise_measurement(enum ima_hoo= ks func, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, int xattr_len, - const struct modsig *modsig) + const struct modsig *modsig, bool bprm_is_check) { return INTEGRITY_UNKNOWN; } diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima= /ima_appraise.c index 5149ff4fd50d..ea2079417318 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -470,17 +470,6 @@ int ima_check_blacklist(struct ima_iint_cache *iint, return rc; } =20 -static bool is_bprm_creds_for_exec(enum ima_hooks func, struct file *file) -{ - struct linux_binprm *bprm; - - if (func =3D=3D BPRM_CHECK) { - bprm =3D container_of(&file, struct linux_binprm, file); - return bprm->is_check; - } - return false; -} - /* * ima_appraise_measurement - appraise file measurement * @@ -492,7 +481,7 @@ static bool is_bprm_creds_for_exec(enum ima_hooks func,= struct file *file) int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *i= int, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, - int xattr_len, const struct modsig *modsig) + int xattr_len, const struct modsig *modsig, bool bprm_is_check) { static const char op[] =3D "appraise_data"; int audit_msgno =3D AUDIT_INTEGRITY_DATA; @@ -514,7 +503,7 @@ int ima_appraise_measurement(enum ima_hooks func, struc= t ima_iint_cache *iint, * of the script interpreter(userspace). Differentiate kernel and * userspace enforced integrity audit messages. */ - if (is_bprm_creds_for_exec(func, file)) + if (bprm_is_check) audit_msgno =3D AUDIT_INTEGRITY_USERSPACE; =20 /* If reading the xattr failed and there's no modsig, error out. */ diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima= _main.c index 5770cf691912..36ce07063dc7 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -236,7 +236,7 @@ static void ima_file_free(struct file *file) static int process_measurement(struct file *file, const struct cred *cred, struct lsm_prop *prop, char *buf, loff_t size, int mask, enum ima_hooks func, - enum kernel_read_file_id read_id) + enum kernel_read_file_id read_id, bool bprm_is_check) { struct inode *real_inode, *inode =3D file_inode(file); struct ima_iint_cache *iint =3D NULL; @@ -426,7 +426,7 @@ static int process_measurement(struct file *file, const= struct cred *cred, inode_lock(inode); rc =3D ima_appraise_measurement(func, iint, file, pathname, xattr_value, - xattr_len, modsig); + xattr_len, modsig, bprm_is_check); inode_unlock(inode); } if (!rc) @@ -493,14 +493,14 @@ static int ima_file_mmap(struct file *file, unsigned = long reqprot, =20 if (reqprot & PROT_EXEC) { ret =3D process_measurement(file, current_cred(), &prop, NULL, - 0, MAY_EXEC, MMAP_CHECK_REQPROT, 0); + 0, MAY_EXEC, MMAP_CHECK_REQPROT, 0, false); if (ret) return ret; } =20 if (prot & PROT_EXEC) return process_measurement(file, current_cred(), &prop, NULL, - 0, MAY_EXEC, MMAP_CHECK, 0); + 0, MAY_EXEC, MMAP_CHECK, 0, false); =20 return 0; } @@ -584,7 +584,7 @@ static int ima_bprm_check(struct linux_binprm *bprm) =20 security_current_getlsmprop_subj(&prop); return process_measurement(bprm->file, current_cred(), - &prop, NULL, 0, MAY_EXEC, BPRM_CHECK, 0); + &prop, NULL, 0, MAY_EXEC, BPRM_CHECK, 0, bprm->is_check); } =20 /** @@ -614,7 +614,7 @@ static int ima_creds_check(struct linux_binprm *bprm, c= onst struct file *file) =20 security_current_getlsmprop_subj(&prop); return process_measurement((struct file *)file, bprm->cred, &prop, NULL, - 0, MAY_EXEC, CREDS_CHECK, 0); + 0, MAY_EXEC, CREDS_CHECK, 0, false); } =20 /** @@ -662,7 +662,7 @@ static int ima_file_check(struct file *file, int mask) security_current_getlsmprop_subj(&prop); return process_measurement(file, current_cred(), &prop, NULL, 0, mask & (MAY_READ | MAY_WRITE | MAY_EXEC | - MAY_APPEND), FILE_CHECK, 0); + MAY_APPEND), FILE_CHECK, 0, false); } =20 static int __ima_inode_hash(struct inode *inode, struct file *file, char *= buf, @@ -881,7 +881,7 @@ static int ima_read_file(struct file *file, enum kernel= _read_file_id read_id, func =3D read_idmap[read_id] ?: FILE_CHECK; security_current_getlsmprop_subj(&prop); return process_measurement(file, current_cred(), &prop, NULL, 0, - MAY_READ, func, 0); + MAY_READ, func, 0, false); } =20 const int read_idmap[READING_MAX_ID] =3D { @@ -925,7 +925,7 @@ static int ima_post_read_file(struct file *file, char *= buf, loff_t size, func =3D read_idmap[read_id] ?: FILE_CHECK; security_current_getlsmprop_subj(&prop); return process_measurement(file, current_cred(), &prop, buf, size, - MAY_READ, func, read_id); + MAY_READ, func, read_id, false); } =20 /** --=20 2.43.0