From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796217820; b=qpjH1xN86b4Zme+KRv1O2fnwNas4p+uGNrj5x7WXsovIVvb/OzcTH0TQHeFR/LAdowwL 2A6YACNp15M95mbRGBK/tA3arl1a/2VriyQBNOXh+tYhVv4St8aRM3vIB2NMg8dBmiLU8 aan1/b3a9W2Lxq+OaT/ZJTWop4KqVCkgoJwIUeY3RgdkEclyjg93ZZoNg7Jl+fc8CHp87 OpkbnAvL+TnpR39sZGI9svixT1ndS/o45ArMoJgNdn9fhoAsiasRjSQfljFySk+3W5zLQ UEGWzPGaAq0tgU29ntSuDn5pHYVPUU8yB3zzBXm3KDCYjoH0UAdvNr1v38XDissiKgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217820; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Mime-Version:Content-Type: Date:Message-Id:Subject:Cc:From:To:References:In-Reply-To: X-Scanned-By; bh=B9NYOsHWNH2l3DBsJKQt+gk0eJJcg/tq/vZSodpfl+E=; b=kolWilYgKm6A0F4Vt1f7m+WP+DXQFkrMTl2BGJkDXCCiam1Bf5DOuHdReaogCAcs0q/w kBFD9GZCNOxlPdQvZo9G3wECht83vcmZYmggDx0kPtceW88iccCI1QHFrSnL6dOTRdLPH G4NTbcDNXWbSG+XFdynZ0i1UEOeJwHeb/OvgUCARwXJM4bu9bJkAe1OHDXK6ZC3P3F+oO V1R2x95fu25zicMxI2IddhS/QO0vefgQHDTjNxgynwK2/+ajS58UgzWBPs0YYYcuvjOpn KFX2wCay5fcPRbnsfX04hty/nwvzRM9RypqvwdjogKw7wZzO/Fiu/hZWcRuNqGavl4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UhWfXo2n; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6563D606A683 for ; Wed, 2 Dec 2026 13:23:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6563D606A683 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UhWfXo2n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796217818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=B9NYOsHWNH2l3DBsJKQt+gk0eJJcg/tq/vZSodpfl+E=; b=UhWfXo2ns5YIduzv+KSC7VZIZRZG6y4QuHY7j0jqLB1T508s6UxxTHW6VhbYFpK5IKLYlk XGkxzStNEpZDFQ63lbfNU0Si+vBIpoHXOzYvFOIHIQ3nfy0pB6k4q6JYdmyhuIXdcNHAiA eW/kTumg+19oKpgf0YhufLTRNSTpCek= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-sXo2NgWwMPCqqCKOXw_0qw-1; Wed, 2 Dec 2026 13:23:32 +0000 X-MC-Unique: sXo2NgWwMPCqqCKOXw_0qw-1 X-Mimecast-MFC-AGG-ID: sXo2NgWwMPCqqCKOXw_0qw_1796217810 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7935E191AAA0; Wed, 2 Dec 2026 13:23:29 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E1CD180157B; Wed, 2 Dec 2026 13:23:28 +0000 (UTC) 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-Type: multipart/signed; boundary=116d74ceea450751a471ecac27a553a5c3e1590a308a840c62748fbb9178; micalg=pgp-sha256; protocol="application/pgp-signature" Date: Wed, 02 Dec 2026 10:23:27 -0300 Message-Id: Subject: Re: [PATCH v2] ima: Fix out-of-bounds read in ima_read_policy() Cc: , , , "Roberto Sassu" From: "Bruno Meneguele" To: "Roberto Sassu" , , , , , , , References: <20261202105724.3056284-1-roberto.sassu@huaweicloud.com> In-Reply-To: <20261202105724.3056284-1-roberto.sassu@huaweicloud.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 --116d74ceea450751a471ecac27a553a5c3e1590a308a840c62748fbb9178 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8; format=Flowed On Wed Dec 2, 2026 at 7:57 AM -03, Roberto Sassu wrote: > From: Roberto Sassu > > ima_read_policy() reads the policy file with kernel_read_file_from_path() > and splits it into rules with strsep(). However, the buffer allocated by > kernel_read_file_from_path() is exactly the size of the file and is not > NUL-terminated. If the policy file does not end with a newline, strsep() > scans past the end of the buffer while looking for the next separator. If > the file size is a multiple of PAGE_SIZE, the scan reaches the vmalloc > guard page and the kernel oopses. > > To avoid the problem, reject the read policy if does not end with a newli= ne > or the NUL terminator. > > Fixes: 7429b092811f ("ima: load policy using path") > Reported-by: Fabrice Derepas > Closes: https://lore.kernel.org/linux-integrity/20260814085443.1211989-1-= fabrice.derepas@canonical.com/ > Suggested-by: Mimi Zohar > Signed-off-by: Roberto Sassu > --- > security/integrity/ima/ima_fs.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima= _fs.c > index 2a0bca554316..872b2c31ca02 100644 > --- a/security/integrity/ima/ima_fs.c > +++ b/security/integrity/ima/ima_fs.c > @@ -548,6 +548,12 @@ static ssize_t ima_read_policy(char *path) > rc =3D 0; > > datap =3D data; > + > + if (size && datap[size - 1] !=3D '\n' && datap[size - 1] !=3D '\0') { > + vfree(data); > + return -EINVAL; > + } > + > while (size > 0 && (p =3D strsep(&datap, "\n"))) { > pr_debug("rule: %s\n", p); > rc =3D ima_parse_add_rule(p); May I suggest an addition to [1] about it? That's literally an invisible fa= ilure the user won't find out the reason easily. [1] https://github.com/linux-integrity/ima-doc Acked-by: Bruno Meneguele -- Bruno Meneguele PGP Key: http://bmeneg.com/pubkey.txt --116d74ceea450751a471ecac27a553a5c3e1590a308a840c62748fbb9178 Content-Type: application/pgp-signature -----BEGIN PGP MESSAGE----- wsCpBAEBCABdBYJrEBvPCRBh1GQVH5GiQzUUAAAAAAAcABBzYWx0QG5vdGF0aW9u cy5vcGVucGdwanMub3JnnmQad2F+X3NeyXWrCh1xOhYhBHVqOp0252XWw5l7rWHU ZBUfkaJDAADHagf9FOWVcSNxpX9eQonaXy1MNAy0VzOI0+CtyvGNvq6URcahKf55 UfOuZZ6NRNvy1n/kcP3nnLRQBhu4Hh1msq9/2Zt0jbZClxeyP+eOTGM2aG/h+DUN Fo8Yay4Rgh04v1HJmQV5IC6XxtAbgdOUZY5VQfgm7OtgP2l/RoHv9tdto3mfguZs 9HpVwUo5Mp4xYnjw9/HcDiv4K/SrtlCVUwz81ZZvt/bQbknC3uCEtnTQPbh5/Fw6 sIrfGaoXEANqpFmqVogN2WWvMLsQzY4bPz5ExQqsGamRHxH4+MIokujJUZcW0uqs 9rFmK/P93ugJMtD/W4njC/paxpZ06jxAt0NGsA== =ckRv -----END PGP MESSAGE----- --116d74ceea450751a471ecac27a553a5c3e1590a308a840c62748fbb9178--