Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1049762pxb; Thu, 24 Mar 2022 11:47:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIPXiI6fjMJkDe9epw4/3H0RSQWiY9HRyOUulE3grJ1GGiibhigftKuanbwk99WL99H5Y6 X-Received: by 2002:a17:902:cf08:b0:151:9d28:f46f with SMTP id i8-20020a170902cf0800b001519d28f46fmr7270222plg.53.1648147652312; Thu, 24 Mar 2022 11:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648147652; cv=none; d=google.com; s=arc-20160816; b=PAwqUTt46PYoRqTaPWpgtoXfrqO0K1VAH2OOMh99I3g7xI6nNCa9s1OsL/dFxE7zEK ysCvcHGICVjikPQtMoFVwRTmwveNH3Mg94f0enMCNJA/JbINd/VGikooAJAV42oLbAjk zM70cNFl7V+tHkZTkS+i5Jfnj606ABZfqtJPCqeXjasRVjMSHgFv6RjdqB2aIpbHRvQ0 dlr6ZYNlO3iw9t/TmViu3MkF1Czr8uXEQtDFRDkvwEis3CZMhOswabm+Xs5+1wcDMx6G CH8X40qHbVIGoVud8B/MF7MIMmseAnEFiceoSr+Dd4jdJLZJE7+3SBmEJGH0dfZptxq+ pktQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=gFwebXzeriQdk2MB7gqMwaHDx1Y3gMzCD/ItoJDCb3c=; b=zyLTD9fVPXMRxdgPsRGaq3cQA7qGYsfCOKfIfnrNaK+jL6uCyagM1eK7OVWRHWM2MF u7QigjWYFiJxYPBJhRbTXl6tv+bjWmFNbo/ar4xi+jwdcOUSyrWmVcVPSeG9EvSkp0om wp0lA4R+fIKi4hxd9Mdy+EqvxeWKGTG7ZQ3RNu1dvAM09tpveBJ5ATYOR+bUZbEjs1JV LS8CieRdvmRMpW/wX4WuH2t4f5TOw5s/OGuHQ3kmUFo51gNMkMXRfVijfv+5nb7EOE2r I96vCTVQldNH9dQQsRRpSpHZBh+OFWlUzeptj5pPLu1BR7IbP0Esqj8gYMyUZJcLyTtw e6+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="oUXoXm/Z"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020aa78183000000b004fa3a8e005csi392254pfi.275.2022.03.24.11.47.15; Thu, 24 Mar 2022 11:47:32 -0700 (PDT) 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=pass header.i=@163.com header.s=s110527 header.b="oUXoXm/Z"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349323AbiCXJqA (ORCPT + 99 others); Thu, 24 Mar 2022 05:46:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345516AbiCXJp7 (ORCPT ); Thu, 24 Mar 2022 05:45:59 -0400 Received: from m12-17.163.com (m12-17.163.com [220.181.12.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 366EE9BB84 for ; Thu, 24 Mar 2022 02:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=gFwebXzeriQdk2MB7g qMwaHDx1Y3gMzCD/ItoJDCb3c=; b=oUXoXm/Z0xDSpS1siVo411ccGqKX43npZh uChgX+w1x9hl8lNY9GP4cDtiZ0j8CSTvZb/gKM0tKx+TMl4Qw/CKgWnVSfTPtSKE T7Y5Llu8iZkOsoisAmiQgZAon+SrGCL6y42xbvZhSOV2L8TsJkDmM36xtoTGPBGa 1vIbV9kwE= Received: from localhost (unknown [159.226.95.33]) by smtp13 (Coremail) with SMTP id EcCowAAn8QJ0PTxieonmIg--.15948S2; Thu, 24 Mar 2022 17:44:21 +0800 (CST) From: QintaoShen To: keescook@chromium.org Cc: linux-kernel@vger.kernel.org, QintaoShen Subject: [PATCH v1] lkdtm/fortify: Check for NULL return of kmalloc() Date: Thu, 24 Mar 2022 17:44:19 +0800 Message-Id: <1648115059-12026-1-git-send-email-unSimple1993@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: EcCowAAn8QJ0PTxieonmIg--.15948S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw4xWFW5Kw13tryUAw4fKrg_yoW3XFb_Gw 4rXr1xJr9xWw1UKw17tFZxZrW0kF1kuFs5u3Zxt3y3Jry7ZF1Iqa40qr98Gw4fGrWkZF9x Cr1DAasY9r17KjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7VUbgTm5UUUUU== X-Originating-IP: [159.226.95.33] X-CM-SenderInfo: 5xqvxz5sohimizt6il2tof0z/1tbiXxXNH1153xfsJwAAs- X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The memory allocation function kmalloc() may return a NULL pointer. If 'src' is NULL, the strscpy() would copy the string to a NULL address. Therefore, it is better to check the return value of kmalloc() to avoid the confusion. Signed-off-by: QintaoShen --- drivers/misc/lkdtm/fortify.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c index ab33bb5..93eeaef 100644 --- a/drivers/misc/lkdtm/fortify.c +++ b/drivers/misc/lkdtm/fortify.c @@ -41,6 +41,9 @@ void lkdtm_FORTIFIED_SUBOBJECT(void) char *src; src = kmalloc(size, GFP_KERNEL); + if (!src) + return ; + strscpy(src, "over ten bytes", size); size = strlen(src) + 1; -- 2.7.4