From patchwork Wed Mar 1 20:27:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 63087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3854806wrd; Wed, 1 Mar 2023 12:35:03 -0800 (PST) X-Google-Smtp-Source: AK7set8XUSMi4CH1BmZHTBFG6OyYQnhhxkP/BHBsQCk0h/MhsRk7f99f0HwPlIuu8ohf82s/oKHi X-Received: by 2002:a17:907:2043:b0:8af:4120:63a8 with SMTP id pg3-20020a170907204300b008af412063a8mr8640163ejb.68.1677702902876; Wed, 01 Mar 2023 12:35:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677702902; cv=none; d=google.com; s=arc-20160816; b=B7eo4wTr2e4urtzh1R9u2RNM5iZXxclQ/RyFF4UhgcNT6AJJamxDEyJxOmpfWrUm7r GgQIA/KPl8gH2e0GeS8T5Ulebnn/qvODM2jr2evt//dS7JBajc2OQM716zivLVJcoQg/ Jyrr1nS0inFVy1iMsMoej5o34URNB8DrsnmRz15lEJNolrd6TCa+GonolJV8h8LFj1Zn 3J3nCbb9P6qYnMhs1+1S4PunKNRWgSuVfM8shfm/nzqpr6agwWQepLCUo3aymXC67/yX V5hsiArq62Evp44G43LrAS9k0v3q9wuhDftlMy+BHHptoCPJqD0Q/p5VFN5Cp7lS2Tk5 /IXw== 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=m9MY4elviyzsUNuS1Zd24z+1CUl0ClUFvobQDWR7uRU=; b=hMOog05YV7dXKGwuZt1PtCYjx4br8PH2Y7adHKO2WuDlQU0XNE5tSF6z/ra2VAypGk pjzOqasXCbF5uy1o/ByRRRDll7fKRjkiGS6/I4SUZ9F3Ev5ARhhZrmxjrKEVxekmVujj fqywIZaUeuQH1QB2QvmgdZ5wSTburUU8Z0gpGZ9Gm81UgrjAPyC0G4QHYF2BeKgNQ1hn iMgPUf/2q1ardFZqjBQXEbHbZIHGWYV/lMW/DJ5NivZ8p5KHxJPv9it8W5qGuI5Y/KeB jLVyiYRm74esuSyE4fV3Gzgmd6rdke4HsC8NuV3sUXhaynzlUVJE0I583AwWGyj9xzvO 2u1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=kkl6+nMB; 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 j12-20020a170906278c00b008da5d744f15si3606918ejc.815.2023.03.01.12.34.39; Wed, 01 Mar 2023 12:35:02 -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=kkl6+nMB; 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 S229698AbjCAU2A (ORCPT + 99 others); Wed, 1 Mar 2023 15:28:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjCAU17 (ORCPT ); Wed, 1 Mar 2023 15:27:59 -0500 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB8AEB7D for ; Wed, 1 Mar 2023 12:27:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1677702473; bh=QgZkwG2KJaskVSRysFIed9zv+7/Cb+p1bNFgkMQ4mcc=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=kkl6+nMBxZfQJEUfSXyYBFs2usQ/Tvn00Rs9paf84JZpjq/EYSLvjajxrePRJ+W06 tvUrH0IreHuhhg2k/i4pXDRRRZkwKJSHGdxEQdbtb+jgNGNbi7o+8E9H5CwPf9gSjP 7sgBJdc2yA3hUWJFIjpIoIo+rg2aoaQQyJMNVB8E= Received: by b221-2.in.mailobj.net [192.168.90.22] with ESMTP via ip-20.mailobj.net [213.182.54.20] Wed, 1 Mar 2023 21:27:53 +0100 (CET) X-EA-Auth: R7+3+1I5KkV/6Upk1NJ/PVVMvhlx+h3G2Swayr51HNxGFuQWV9jwEpye02f5r0pQ5K+XoAbwT1C0fRkMUOeZSg== Date: Thu, 2 Mar 2023 01:57:48 +0530 From: Deepak R Varma To: Evgeniy Polyakov , linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH RESEND] 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?1759198999506083826?= X-GMAIL-MSGID: =?utf-8?q?1759198999506083826?= 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. - Resending the patch for review and feedback. Initially sent on Dec 23 2022. drivers/w1/w1.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 9d199fed9628..0241fc6ca65a 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);