From patchwork Thu Dec 22 22:39:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 35979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp25232wrn; Thu, 22 Dec 2022 14:45:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXsU3VB5YyZbTvOFXoZ8Zs4oC5H60KoZkplOlAjjISaeC+obQIrimIMAPpeFYOKNypW9bNJk X-Received: by 2002:a17:906:2349:b0:7c1:844d:7447 with SMTP id m9-20020a170906234900b007c1844d7447mr5887676eja.35.1671749143969; Thu, 22 Dec 2022 14:45:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671749143; cv=none; d=google.com; s=arc-20160816; b=zTD9yZLXTaxs2GdWwxyBocwqcAe3dtrUmF01R5sJScOzD5skrLg4f214Pw6lAfI3Y7 lzQ0r13hpLuaIa1I107Da48NG02ARz5YJmw8IufJQwfHM1eww8Xdh3glLGwBhpQWVkEV dkTRybzECEaAq1GICmMzdkAyNUDEQ+phi6KPu3I9onZ2UzqT5q/Qt5BaMfmlKxQC9G1S WeGokxPTtaRm6gitV0RNB0uaBDuvfqEdrJqwo3RhYCIjbzWgv1ggPHumMmHJZcn/qs97 dvXiFiVk02u4fIMRd8DG5ynmNrcteqlb4YObxO367QocAorDPbHHyHRWpf72VssG1qKm 349g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=2A4alGeDhyyat+LHkbB/dHPb1Yxd06wWPgNb2XMnn9k=; b=DRduIO6GWxXM1FD8WVmzhlTXSOJVerUoxqhWRfHau9uwd2+I+CJ9ieXk8MNQyDAv93 N+YefsHmvxktMnBEC24sSXfuJHHaOxkS572cUGY8MKMYieJjDiEuWY3hMR0vweOCx3zk tfFz5O/UFlZe+w3eIv19/ZSD0f5ixb37lQOUz5kbGey02ZvWaLu8vHFFfSRVummDdFLv 70PYWT7NYPjlqyzdfVWynOV6VyTLvrkYajtmDBm0bLa3HION+lbn4m40q03o0/bPJh4L vRv3aGTYQ2S65w8aqDWHn3KZ6rKWhudTpBG1xhay1vAm9TxQcYdo2RKhlLeQFuV1bdJJ RKmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=aFgIbMQu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd10-20020a170907628a00b008241a5eece4si1253489ejc.102.2022.12.22.14.45.20; Thu, 22 Dec 2022 14:45:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=aFgIbMQu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235789AbiLVWjg (ORCPT + 99 others); Thu, 22 Dec 2022 17:39:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235442AbiLVWjd (ORCPT ); Thu, 22 Dec 2022 17:39:33 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCB9EA45A for ; Thu, 22 Dec 2022 14:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1671748768; bh=z8J0zWp2xScShPwwVbxBi7EfLHWTA83YkulZZUzCqCQ=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=aFgIbMQuvk47ps7/6m0SiLneAD6PXfeS8OXXpWTad9L2GZueB95X/dylAKf6RmlVd UchTzqfQ4ZhkRRZG2NUL1Llh1UBkXW41H2NSciMfBk16iA5uIxmUET1Sv19KC7T393 kFYlKe+CrwjdYeAR5WyXOrYC/d3w/Uhw3rWVrf8c= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via ip-206.mailobj.net [213.182.55.206] Thu, 22 Dec 2022 23:39:27 +0100 (CET) X-EA-Auth: +78mYshc1jvuTVNaSX5oSe5ppaMTDLnPHSBg/6O+0Uud39gcRigBQlR58ttQMV+b52Zi9yOXgzdg46jT2cnOtwo3GGkxzO5I Date: Fri, 23 Dec 2022 04:09:22 +0530 From: Deepak R Varma To: Evgeniy Polyakov , linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , drv@mailo.com Subject: [PATCH] w1: Use kfree_sensitive to clear sensitive information Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752956030283813370?= X-GMAIL-MSGID: =?utf-8?q?1752956030283813370?= Replace combination of 'memset(0) + kfree()' by kfree_sensitive() as it prevents compiler from optimizing away from zeroing out memory at the end of a scope. kfree_sensitive() is also safe in case the memory pointer turns out to be null, which simply gets ignored. Issue identified using kfree_sensitive.cocci coccinelle semantic patch. Signed-off-by: Deepak R Varma --- Note: proposed change is compile tested only. drivers/w1/w1.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.34.1 diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index f2ae2e563dc5..e08467e08b73 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev) struct w1_master *md = dev_to_w1_master(dev); dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name); - memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master)); - kfree(md); + kfree_sensitive(md); } static void w1_slave_release(struct device *dev) @@ -805,9 +804,10 @@ int w1_unref_slave(struct w1_slave *sl) w1_family_notify(BUS_NOTIFY_DEL_DEVICE, sl); device_unregister(&sl->dev); #ifdef DEBUG - memset(sl, 0, sizeof(*sl)); - #endif + kfree_sensitive(sl); + #else kfree(sl); + #endif } atomic_dec(&dev->refcnt); mutex_unlock(&dev->list_mutex);