From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E183520ED; Thu, 13 Jun 2024 12:51:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718283070; cv=none; b=Y8Of750kDZXzq88sLwclSfyU7nIXPqNBkvIvqDjA73ckGWk0VGV9YxfIpKWgtHWbHJE1jJAZw9lJ1vkB8/DgdrBrfSh3hHdDvG9QkKgbB7sC+MN6oy22GbmNIoy2RJr3m+1z5qyPfCVjNddGtNzpgLfCWlREfENUSIG27Eu2JkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718283070; c=relaxed/simple; bh=4Qgo1WefyfOYsir7tSRNbFjydve8Y5fQZ3CywWNHuX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jdotEmUvmU81R+Qiziw8lUuGDilwb23gTDxMfaXC5Ax/ooAn17S5ADGXt/mY29LKIW0gY8Lzu3sttoEO4f4pirG2GfORdypfS1T0JIzwmWYkkCWVIgqIEuFo7g6eN/oRBkZXufKqYkXVN8IkXkw8Bxal9+U35fzSstpZzZMzjf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bQS0LOPp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bQS0LOPp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D6B0C2BBFC; Thu, 13 Jun 2024 12:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718283069; bh=4Qgo1WefyfOYsir7tSRNbFjydve8Y5fQZ3CywWNHuX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQS0LOPpvkoatswAT9c25x/cEp/sHhuI6PY/LPKC3RiAEIQGEvqjpiMyA4SUOWwHw ueB39UYo6kbwdndXozNjQk+AIkYeO6EhIPFU3YHfGxyYYdeJCZeTrIOC7l0qn0aIQZ 0NcmGxTvQPKtD2rZcKTixF8zCkF9iYrUjd1EM/4w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexander Potapenko , Brian Johannesmeyer , Marco Elver , Dmitry Vyukov , Kees Cook , Andrew Morton Subject: [PATCH 6.1 58/85] kmsan: do not wipe out origin when doing partial unpoisoning Date: Thu, 13 Jun 2024 13:35:56 +0200 Message-ID: <20240613113216.377891197@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113214.134806994@linuxfoundation.org> References: <20240613113214.134806994@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Potapenko commit 2ef3cec44c60ae171b287db7fc2aa341586d65ba upstream. As noticed by Brian, KMSAN should not be zeroing the origin when unpoisoning parts of a four-byte uninitialized value, e.g.: char a[4]; kmsan_unpoison_memory(a, 1); This led to false negatives, as certain poisoned values could receive zero origins, preventing those values from being reported. To fix the problem, check that kmsan_internal_set_shadow_origin() writes zero origins only to slots which have zero shadow. Link: https://lkml.kernel.org/r/20240528104807.738758-1-glider@google.com Fixes: f80be4571b19 ("kmsan: add KMSAN runtime core") Signed-off-by: Alexander Potapenko Reported-by: Brian Johannesmeyer Link: https://lore.kernel.org/lkml/20240524232804.1984355-1-bjohannesmeyer@gmail.com/T/ Reviewed-by: Marco Elver Tested-by: Brian Johannesmeyer Cc: Dmitry Vyukov Cc: Kees Cook Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/kmsan/core.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- a/mm/kmsan/core.c +++ b/mm/kmsan/core.c @@ -258,8 +258,7 @@ void kmsan_internal_set_shadow_origin(vo u32 origin, bool checked) { u64 address = (u64)addr; - void *shadow_start; - u32 *origin_start; + u32 *shadow_start, *origin_start; size_t pad = 0; KMSAN_WARN_ON(!kmsan_metadata_is_contiguous(addr, size)); @@ -287,8 +286,16 @@ void kmsan_internal_set_shadow_origin(vo origin_start = (u32 *)kmsan_get_metadata((void *)address, KMSAN_META_ORIGIN); - for (int i = 0; i < size / KMSAN_ORIGIN_SIZE; i++) - origin_start[i] = origin; + /* + * If the new origin is non-zero, assume that the shadow byte is also non-zero, + * and unconditionally overwrite the old origin slot. + * If the new origin is zero, overwrite the old origin slot iff the + * corresponding shadow slot is zero. + */ + for (int i = 0; i < size / KMSAN_ORIGIN_SIZE; i++) { + if (origin || !shadow_start[i]) + origin_start[i] = origin; + } } struct page *kmsan_vmalloc_to_page_or_null(void *vaddr)