From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E8A0C433E0 for ; Mon, 29 Jun 2020 19:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DD392072D for ; Mon, 29 Jun 2020 19:20:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593458428; bh=WEhn6K+T8CG8Gtu1lKNFABAEEl2O15fFlFTcYiimaF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=keVJJLfp9QsTZMgIG5dW3TSIiJHfOVX01+8V5n7CryQN3i5/knVdCv14UBaXPR0Za ueEbodFXI3WpKJcPbel/ui7T1d1uNhS9+VnUYnJEfuZh7Q/dKwDw3clpWk7QX4qX6f nq8QWj48hC1fbqxSmhxutH7A99zfH38pI5hYk+bU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732127AbgF2TU0 (ORCPT ); Mon, 29 Jun 2020 15:20:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:33186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727020AbgF2TUS (ORCPT ); Mon, 29 Jun 2020 15:20:18 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B239925476; Mon, 29 Jun 2020 15:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593445433; bh=WEhn6K+T8CG8Gtu1lKNFABAEEl2O15fFlFTcYiimaF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LA/FSPedMBIcjuaJQ30CZV5c4bUALqVNpy4iR6w8ekn0jHsSoeb/kb/AJ8BQeNTTe L4YvQSeBNUNiwKxuGdFSg5COg+BWbRTLdWXPsUVqNVKsXvmrjDg+Mr6iKUZlT/qzZT z7Mc14JJem+JmXAkM9fRneUfGYQqwlP5UDrXZG5o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Waiman Long , Michal Hocko , David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Joe Perches , Matthew Wilcox , David Rientjes , Johannes Weiner , Dan Carpenter , "Jason A . Donenfeld" , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman Subject: [PATCH 4.9 178/191] mm/slab: use memzero_explicit() in kzfree() Date: Mon, 29 Jun 2020 11:39:54 -0400 Message-Id: <20200629154007.2495120-179-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629154007.2495120-1-sashal@kernel.org> References: <20200629154007.2495120-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.229-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.229-rc1 X-KernelTest-Deadline: 2020-07-01T15:39+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long commit 8982ae527fbef170ef298650c15d55a9ccd33973 upstream. The kzfree() function is normally used to clear some sensitive information, like encryption keys, in the buffer before freeing it back to the pool. Memset() is currently used for buffer clearing. However unlikely, there is still a non-zero probability that the compiler may choose to optimize away the memory clearing especially if LTO is being used in the future. To make sure that this optimization will never happen, memzero_explicit(), which is introduced in v3.18, is now used in kzfree() to future-proof it. Link: http://lkml.kernel.org/r/20200616154311.12314-2-longman@redhat.com Fixes: 3ef0e5ba4673 ("slab: introduce kzfree()") Signed-off-by: Waiman Long Acked-by: Michal Hocko Cc: David Howells Cc: Jarkko Sakkinen Cc: James Morris Cc: "Serge E. Hallyn" Cc: Joe Perches Cc: Matthew Wilcox Cc: David Rientjes Cc: Johannes Weiner Cc: Dan Carpenter Cc: "Jason A . Donenfeld" Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 13f1926f8fcd4..26c4d47229273 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1345,7 +1345,7 @@ void kzfree(const void *p) if (unlikely(ZERO_OR_NULL_PTR(mem))) return; ks = ksize(mem); - memset(mem, 0, ks); + memzero_explicit(mem, ks); kfree(mem); } EXPORT_SYMBOL(kzfree); -- 2.25.1