From patchwork Fri Feb 28 20:55:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 13997129 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDF841C54B2 for ; Fri, 28 Feb 2025 20:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740776135; cv=none; b=r5YU5MjTli4ZOOZuOUPwu4FPutApyUxYl9DcuMIaB1kfHm69VMnlqD7HaWqROFQ02w0E/TwqQlr0bMqD39RRip6XeWirOuFXnA1pHEZMz0r9GcAzoSH5rOh3NIPe2xFSYrYjYVdjeZxBFG0pPd+V0E/tWUjvf9vIacBdz3v0XT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740776135; c=relaxed/simple; bh=ftb1+KM4CygywhTSZuLLFR5O/mFZCEba9+dJOa0070Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GuQRxtog28dPUjUvXeKVyikMdD4x7ynYDz8hCPYvTMpKEaD+WsMrkLBmy6inHYCw8DVJbj9UM2TO3w/5Df8ud4j7rfXXkpZoxBr9Vkdk4VMA1VqsgJ+YY3gJQegaQu0Ew56d9KVQbhrY5ov4vIKiE3nuj2vGlKn+YHGcouLN2Gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=W1hn/NhM; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="W1hn/NhM" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51SDXjuc029263; Fri, 28 Feb 2025 20:55:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=xMewSHS2CgmKE5APk SyR7dfgF/p4a7etf3qDdzc30rY=; b=W1hn/NhMUh6a1jvX2szoTnzBoaGmLBCoG Itd+f7fvrEG/K90H3iJ7Eqxn7GTYCYEk3IaGeB1lSGkcdx8r9Lvc8cEpHfZFvcxM 5quEBKgHvzpb7Zy5I5oNIDBTc9aEcWLeWc3b2AR2ev2vB4QVdXoicPnxcFIRMQMd IyJOLPIeB4JojvW9OdilV6OTITUW1TeEWGFpxHL8ZcNR4f9zjm4g3YXN6DoLCgq/ HyJRCcug/aIGpksiqRoyfD+prVNb3Rbref06F+q9Srd3yZXzlU1l+iz0WUh64McR rud77dmafoHr/+D6Tv0RB02VEY2heaaTpd6p6VkbKyso3ArkFOpew== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 453400mxuc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Feb 2025 20:55:22 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51SIHXZu027337; Fri, 28 Feb 2025 20:55:22 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 44yum2g5k1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Feb 2025 20:55:22 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51SKtI1Q32178530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Feb 2025 20:55:18 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 585F220043; Fri, 28 Feb 2025 20:55:18 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E715720040; Fri, 28 Feb 2025 20:55:16 +0000 (GMT) Received: from li-43857255-d5e6-4659-90f1-fc5cee4750ad.ibm.com.com (unknown [9.61.94.47]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 28 Feb 2025 20:55:16 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , roberto.sassu@huawei.com, Stefan Berger , Petr Vorel Subject: [PATCH v2 1/2] ima: limit the number of open-writers integrity violations Date: Fri, 28 Feb 2025 15:55:04 -0500 Message-ID: <20250228205505.476845-2-zohar@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228205505.476845-1-zohar@linux.ibm.com> References: <20250228205505.476845-1-zohar@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7gyh4ZYzYWM2mInryC5lN0076hqYupD3 X-Proofpoint-ORIG-GUID: 7gyh4ZYzYWM2mInryC5lN0076hqYupD3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-28_06,2025-02-28_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2502280148 Each time a file in policy, that is already opened for write, is opened for read, an open-writers integrity violation audit message is emitted and a violation record is added to the IMA measurement list. This occurs even if an open-writers violation has already been recorded. Limit the number of open-writers integrity violations for an existing file open for write to one. After the existing file open for write closes (__fput), subsequent open-writers integrity violations may be emitted. Tested-by: Stefan Berger Reviewed-by: Petr Vorel Tested-by: Petr Vorel Signed-off-by: Mimi Zohar --- Changelog v2: - Based on Roberto's review, renamed the atomic flag name, updated the patch description. - Added Petr's and Stefan's tags. Changelog v1: - Basesd on Stefan's RFC comments, updated the patch description and code: removed unnecessary checks, simplified code. security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_main.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) -- 2.48.1 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index a4f284bd846c..3423b3088de5 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -182,6 +182,7 @@ struct ima_kexec_hdr { #define IMA_CHANGE_ATTR 2 #define IMA_DIGSIG 3 #define IMA_MUST_MEASURE 4 +#define IMA_EMITTED_OPENWRITERS 5 /* IMA integrity metadata associated with an inode */ struct ima_iint_cache { diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 28b8b0db6f9b..95118c1887cb 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -137,8 +137,13 @@ static void ima_rdwr_violation_check(struct file *file, } else { if (must_measure) set_bit(IMA_MUST_MEASURE, &iint->atomic_flags); - if (inode_is_open_for_write(inode) && must_measure) - send_writers = true; + + /* Limit number of open_writers violations */ + if (inode_is_open_for_write(inode) && must_measure) { + if (!test_and_set_bit(IMA_EMITTED_OPENWRITERS, + &iint->atomic_flags)) + send_writers = true; + } } if (!send_tomtou && !send_writers) @@ -167,6 +172,8 @@ static void ima_check_last_writer(struct ima_iint_cache *iint, if (atomic_read(&inode->i_writecount) == 1) { struct kstat stat; + clear_bit(IMA_EMITTED_OPENWRITERS, &iint->atomic_flags); + update = test_and_clear_bit(IMA_UPDATE_XATTR, &iint->atomic_flags); if ((iint->flags & IMA_NEW_FILE) || From patchwork Fri Feb 28 20:55:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 13997132 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 944D71BCA0E for ; Fri, 28 Feb 2025 20:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740776137; cv=none; b=hfzKWF0/vWBjEduJ0f6xSVnqRvYwNnztiTK0XwNe/BhlnJY810ZSD1Wz2DWH5gzx1r3bJQmFnwOD998R/7e7HERk2ZnRHEzoV6aPIU/kUpLbwjH1llu684fIQC8Vf1l/VV4IoQ315Ur3c6nXZPP6KcUK7tEunb5yQzkmScaDfqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740776137; c=relaxed/simple; bh=mbGn3NPdNP+a59nXzr+JrntI6znar5qKyqw6huZRiFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p55OTx0tqYbSw19rEGjfFLDK0a5Nmh06RhLGpAuAViTBd+lt4kvnQdqAmsc3ANsJr7YRqtdjVMzNRGMzjLS/gqQTTkEpV/ZR3A2G4Ao1wDN1TYVu+T57NnU7v5JtZ8MpcMYLc1YBmeJl/nYoBn+MAY+hpRP2YZBynvQDZcdrEgM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=muniTs6A; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="muniTs6A" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51SJaQFa015651; Fri, 28 Feb 2025 20:55:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=7TkAxx9U7T0kN+B2H HzQupk+wbLfn5Q3Jqm+06qmABk=; b=muniTs6AF/jL37JGiohhyhMZbr5LsdjKL 2sPuXUe7gSZj48wTI6RvTMBS1QUi8RwRZ5RR0o+MteUqZMesaxZG2/hbaDaMXJ7P YQZb5fV0mZey3xa/221Xy3FB8Jq5/zKMys9k0GqoRFBITdl5y4wnfqvyFyFPiNP2 Oq7e77wmUx1ufYQ4oFCnziMH/Q67OkewbrAhszv6Jej3XfcRYuu1oOc0Z1X6y1dd lDW3koLYdhPqS3SvLv6AzShSvtSKvrDK0srLetNmuWt2BgDNV7eaEXXQYZAfRFcu ol0HrjyYML4lpDnw+RlAs2uIbL8/0V3A9WgaN0XaajWlPW38C/uiQ== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45316adxjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Feb 2025 20:55:25 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51SK1cd1026285; Fri, 28 Feb 2025 20:55:24 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 44yswp0kmj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Feb 2025 20:55:24 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51SKtKeO30802666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Feb 2025 20:55:20 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63DCD20043; Fri, 28 Feb 2025 20:55:20 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BBE0920040; Fri, 28 Feb 2025 20:55:18 +0000 (GMT) Received: from li-43857255-d5e6-4659-90f1-fc5cee4750ad.ibm.com.com (unknown [9.61.94.47]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 28 Feb 2025 20:55:18 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , roberto.sassu@huawei.com, Stefan Berger , Petr Vorel Subject: [PATCH v2 2/2] ima: limit the number of ToMToU integrity violations Date: Fri, 28 Feb 2025 15:55:05 -0500 Message-ID: <20250228205505.476845-3-zohar@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228205505.476845-1-zohar@linux.ibm.com> References: <20250228205505.476845-1-zohar@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _FzJdi_XbgNJhNmBsAgvaf_uEsYw6dyW X-Proofpoint-GUID: _FzJdi_XbgNJhNmBsAgvaf_uEsYw6dyW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-28_06,2025-02-28_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 adultscore=0 mlxlogscore=999 spamscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2502280148 Each time a file in policy, that is already opened for read, is opened for write, a Time-of-Measure-Time-of-Use (ToMToU) integrity violation audit message is emitted and a violation record is added to the IMA measurement list. This occurs even if a ToMToU violation has already been recorded. Limit the number of ToMToU integrity violations per file open for read. Note: The IMA_MAY_EMIT_TOMTOU atomic flag must be set from the reader side based on policy. This may result in a per file open for read ToMToU violation. Since IMA_MUST_MEASURE is only used for violations, rename the atomic IMA_MUST_MEASURE flag to IMA_MAY_EMIT_TOMTOU. Tested-by: Stefan Berger Reviewed-by: Petr Vorel Tested-by: Petr Vorel Signed-off-by: Mimi Zohar --- Changelog v2: - Based on Roberto's review, renamed the atomic flag name, updated the patch description. - Added Petr's and Stefan's tags. security/integrity/ima/ima.h | 2 +- security/integrity/ima/ima_main.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) -- 2.48.1 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 3423b3088de5..e0489c6f7f59 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -181,7 +181,7 @@ struct ima_kexec_hdr { #define IMA_UPDATE_XATTR 1 #define IMA_CHANGE_ATTR 2 #define IMA_DIGSIG 3 -#define IMA_MUST_MEASURE 4 +#define IMA_MAY_EMIT_TOMTOU 4 #define IMA_EMITTED_OPENWRITERS 5 /* IMA integrity metadata associated with an inode */ diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 95118c1887cb..f3e7ac513db3 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -129,14 +129,15 @@ static void ima_rdwr_violation_check(struct file *file, if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) { if (!iint) iint = ima_iint_find(inode); + /* IMA_MEASURE is set from reader side */ - if (iint && test_bit(IMA_MUST_MEASURE, - &iint->atomic_flags)) + if (iint && test_and_clear_bit(IMA_MAY_EMIT_TOMTOU, + &iint->atomic_flags)) send_tomtou = true; } } else { if (must_measure) - set_bit(IMA_MUST_MEASURE, &iint->atomic_flags); + set_bit(IMA_MAY_EMIT_TOMTOU, &iint->atomic_flags); /* Limit number of open_writers violations */ if (inode_is_open_for_write(inode) && must_measure) {