From patchwork Fri Feb 17 18:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li zeming X-Patchwork-Id: 57813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp55806wrn; Wed, 15 Feb 2023 18:16:59 -0800 (PST) X-Google-Smtp-Source: AK7set9/UcFP0pE+q9Mjy27hLIen3yc1yJPuwhfSTnKFgBtN0H0LxP1iCubEeh99WqLhKjPRCeNt X-Received: by 2002:a05:6a20:7d85:b0:bf:199e:9b0 with SMTP id v5-20020a056a207d8500b000bf199e09b0mr5050489pzj.49.1676513819582; Wed, 15 Feb 2023 18:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676513819; cv=none; d=google.com; s=arc-20160816; b=DNjHIqqYxaJ2vM42d+ud9mLk5sVn3tCdNP1ttqUEp/jtSDAQ513f1nhr/Axv+QzgS4 4EUZEdU4ySLPBusYPrw7a31/uVyExVOJ7fO/zlTiZuxhgl7KO8SdS+tW/XSG9WZ4Znnt Uk/N9mYgkpXw3Jx6S338E5KJqNt2qNvPDtt4FoFzQAGWv6ZjoOzADThsGbzycNaNJLIQ wcQ9HFKhXf2kh7cITKnFesoMCn6js8BQlKfpbuc72Wz1apxgZucFRL664qWVgJaJjLoR 93sFSFx4Tl/sUmsHSb9jlD0dg88eacT4j+o5NBQSGUWavhL8esls258HWP59MyzuRWjO uGDw== 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; bh=HhdjIpaQlNblYue2rmPC17eovtq4jYkrcQTOUlDoP4k=; b=Tge6uF9XydHyxsLNjeuctLzhVlNx7sdw96n7JG4EO8I8jEeCce4z12Mh5iwWqvcJhT +9nhlONWeuk3Ikt62lNwPksaiO3QAW9ldNF4m/SN2AxEXRpvxSP+iR8XjFMXUBYQB+ov E4y6POtX8x67Y1ai1G20OF6Iy4akWkVigeKPZrvT9eVv3zZUuWihDenzLY82/Nui6NVJ i7OrPwRP0yDt00yHQ8LOXNORZBDz+7Wyu/DGRP4GXI6so5xUs4u4dmbRnOKCCe/bkrML Xz2FKlCcltyd26RZBdDAldN/KUxnR/HlOjdfBQiSotaxLlxCvE1jsLQnNUBKzPpY+6nN 618g== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a634304000000b004fb37e8fd04si232525pga.377.2023.02.15.18.16.45; Wed, 15 Feb 2023 18:16:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjBPCG2 (ORCPT + 99 others); Wed, 15 Feb 2023 21:06:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjBPCGZ (ORCPT ); Wed, 15 Feb 2023 21:06:25 -0500 Received: from mail.nfschina.com (unknown [42.101.60.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EDD42DE0 for ; Wed, 15 Feb 2023 18:06:23 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 18F761A00A29; Thu, 16 Feb 2023 10:06:58 +0800 (CST) X-Virus-Scanned: amavisd-new at nfschina.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D3ysZJGqJFcI; Thu, 16 Feb 2023 10:06:57 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 45A6B1A00856; Thu, 16 Feb 2023 10:06:57 +0800 (CST) From: Li zeming To: keescook@chromium.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Li zeming Subject: [PATCH] fortify: Increase pointer assignment check Date: Sat, 18 Feb 2023 02:37:40 +0800 Message-Id: <20230217183740.3039-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_24_48, RDNS_NONE,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1757952154783636591?= X-GMAIL-MSGID: =?utf-8?q?1757952154783636591?= Increase the check after the src pointer allocates memory. If these two functions are used, at least increase some robustness. Signed-off-by: Li zeming --- drivers/misc/lkdtm/fortify.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c index 015927665678..5c32e4e81d37 100644 --- a/drivers/misc/lkdtm/fortify.c +++ b/drivers/misc/lkdtm/fortify.c @@ -44,6 +44,9 @@ static void lkdtm_FORTIFY_STR_MEMBER(void) char *src; src = kmalloc(size, GFP_KERNEL); + if (src == NULL) + return; + strscpy(src, "over ten bytes", size); size = strlen(src) + 1; @@ -109,6 +112,9 @@ static void lkdtm_FORTIFY_MEM_MEMBER(void) char *src; src = kmalloc(size, GFP_KERNEL); + if (src == NULL) + return; + strscpy(src, "over ten bytes", size); size = strlen(src) + 1;