Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp242551pxa; Thu, 27 Aug 2020 00:30:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpYRDc2DdB6OjCi/d/LhZmQj8188LHAzezjogBKjKW+0JKLiPrIO8JPUiRkwrlLQe/PQS8 X-Received: by 2002:a17:906:d0c9:: with SMTP id bq9mr18849961ejb.475.1598513438733; Thu, 27 Aug 2020 00:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598513438; cv=none; d=google.com; s=arc-20160816; b=gYGbYni2spjyw930oab1UyzNVVSRPLzvnI+wi633XU05uNbS7N8lmFwjlHVNKT2q43 N5FVfXmeLfw1GNvQyCpWlI2ZpBgpYtAaA+q78aPcbrOOShefQ6iwYDR2cQtnwgwoGdPc LV+do24TMJ3HBoXosbDBAHyeKxdzcUZBurbxjAr4aPXFPCEfto5tTjtocSc5slg8lsIy 9vTV0yv10LeHASuEO4UeTqTh+1FuGPKbYUSkhlZWSjKTHLv7fa+VoyjnYKHzNv4FFNqF p5LRFRPhhmxjn7v5xP+o7b+vZAzS8eZs0IyW2U3IlZo/Z6L6QJli4H7IEW2QqeTnzlkk S3hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mi5B+pEaQqn6pQw0ZtzMwgBCvwV3kCOCPtMygdOsJBE=; b=eibzsIk+xVGC5eHSknEFnq9fcl0Q3ntOVFzu3UQM8oayVQ7Q6esZu9Ys4iKRXNB0M0 EMMTYpdbHgVQkfKR5zUPrau9XshGWNILa+5eB7iSxhyPeR7PRyHUy4fMhkpOPoS/mIXo So0dsYH+lO5m7r01KUESsgwJvn7qxx8o85gkS2EyizB8FTll7mC6xFkJmJTDQGaAQCN6 Dje01mYFuDApYWstNX1i6AigHxa83uh0KARao9jpiEESYhjoGqyhgtw02osRi1oewlb5 XxdpLTJgLGQ9WfSzGs5aFNxXo7UlzFTC8ufMLDJVZktJmnMhtQ9JFcYbrV1zqYnra8Mh sazw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si835456ejx.85.2020.08.27.00.30.15; Thu, 27 Aug 2020 00:30:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728087AbgH0H3j (ORCPT + 99 others); Thu, 27 Aug 2020 03:29:39 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41238 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726123AbgH0H3j (ORCPT ); Thu, 27 Aug 2020 03:29:39 -0400 Received: by mail-lj1-f193.google.com with SMTP id f26so5260811ljc.8; Thu, 27 Aug 2020 00:29:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mi5B+pEaQqn6pQw0ZtzMwgBCvwV3kCOCPtMygdOsJBE=; b=ZqIdGucKIQNbUlibmv6J2iC/5brpw9BrQnfLyjIaMsqv03qewVtIEAU0wGnmpXMLkR rVZdnWYRFU6i2gNAfdopfAHJX7mbFkQ4YrDW3jOyvQIGVS9Hsn8P7VAWjYvgCUz6BUf/ j6RcGXay0+zaP7rKVsOQTxNo0Aw/hSSBkRgh4AAvijGSEjdadmqbVeF5vSEZzeNzyHWb yXB4UtN47smYjKiYB1s2qOREEXn4BCOXGpj1HpQknW4/1RURV5aj+wiL+zVSSRHP1hhj yW6MpUjkIdSlgqDk1NclQGJm/M9z6ku+6/2w5Y6ujcCDI/U49fKPg5liZfRckZpEuk7C XIfQ== X-Gm-Message-State: AOAM530QubuNGkBu8LQ5DFiCyv8Bs4yDHPjebvBgn6W24x5EVvCuydKK IDjtjI7f147SvuVXdoR6CPGmsj/I6CM= X-Received: by 2002:a2e:9c86:: with SMTP id x6mr8751433lji.346.1598513376601; Thu, 27 Aug 2020 00:29:36 -0700 (PDT) Received: from localhost.localdomain ([213.87.147.111]) by smtp.googlemail.com with ESMTPSA id m25sm282937ljg.79.2020.08.27.00.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 00:29:36 -0700 (PDT) From: Denis Efremov To: David Howells Cc: Denis Efremov , Jarkko Sakkinen , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] security/keys: use kvfree_sensitive() Date: Thu, 27 Aug 2020 10:29:23 +0300 Message-Id: <20200827072923.14718-1-efremov@linux.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kvfree_sensitive() instead of open-coding it. Signed-off-by: Denis Efremov --- security/keys/big_key.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/security/keys/big_key.c b/security/keys/big_key.c index 691347dea3c1..d17e5f09eeb8 100644 --- a/security/keys/big_key.c +++ b/security/keys/big_key.c @@ -121,8 +121,7 @@ int big_key_preparse(struct key_preparsed_payload *prep) *path = file->f_path; path_get(path); fput(file); - memzero_explicit(buf, enclen); - kvfree(buf); + kvfree_sensitive(buf, enclen); } else { /* Just store the data in a buffer */ void *data = kmalloc(datalen, GFP_KERNEL); @@ -140,8 +139,7 @@ int big_key_preparse(struct key_preparsed_payload *prep) err_enckey: kfree_sensitive(enckey); error: - memzero_explicit(buf, enclen); - kvfree(buf); + kvfree_sensitive(buf, enclen); return ret; } @@ -273,8 +271,7 @@ long big_key_read(const struct key *key, char *buffer, size_t buflen) err_fput: fput(file); error: - memzero_explicit(buf, enclen); - kvfree(buf); + kvfree_sensitive(buf, enclen); } else { ret = datalen; memcpy(buffer, key->payload.data[big_key_data], datalen); -- 2.26.2