From patchwork Sat Mar 25 19:25:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 74325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp108396wrt; Thu, 23 Mar 2023 20:05:11 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcsbC2bJqZoPXZ0XfVRf6xWxz5Bue0bCybU8p9fps/8u+8rwCrNAq0ra/PCnwzMC5xSWj8 X-Received: by 2002:a17:90b:1e43:b0:23d:1b50:1ebe with SMTP id pi3-20020a17090b1e4300b0023d1b501ebemr1174408pjb.27.1679627111038; Thu, 23 Mar 2023 20:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679627111; cv=none; d=google.com; s=arc-20160816; b=lI66EihTFGsRWAkxBAEf6mseoYjQ2Uf7pssY8swgi+DoRVeKo4gfgH+zf/JJvn2FSK yC/8oF6fiVr9+pWt64jVy+1wXeqTEENkra1FHIFhEBphs5lHSFxx0ji3nas1lkC5flOX lZkv0FWV2tafBMXHmX2t8L7ix0aATGL2h0R+Rakps9chGUJcxtS82CUmVttXbjYO2sY7 /4BgtPdkb+XQjDyHLegJJ55qNsFmXXuqyWOP3PXst1sRtaSMtLgXhW5EYU+LOFObL1Gf W7SsfBqvm/EhjTkeEP5sEhTeKTLs5cGiI57XUIRcX1S3MIu3IEa7zXWibX1tA+RfVohp Fung== 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=3jfKp5f1k8IHSomUBgteI7KGvsM6j/Fvi5rQ8PpYEus=; b=DU1rJk2cbjg9zR8dpNjzuGAuLAV2/iDIZQokBiNxW7EbCy5BHFcGtxFZDM0YgjKLhv viPDItoAQhHT5AgowXrcTJeuGgqN8uHBnNGA7zkMeZEBtfhpf3JwVE+3Qth/Hi3Qvl1x TaP/dANXsYatlU36XqdX34+ayy4anhdb4GDF0Yg18/EWQZp42YBNoPWzRTKDpJ2mIgtw PbfJaGTpFpjl2MoNY5Tsi0I4jRDTu/CItDvMyjAzg8yDgr0hz4+TmseVr3ABowV/q/bU +rvHqRa0oEELVL6cuzVFbg3PLejUnoFDHlPf0LiRS5N2WpcnA2Gy1k6kC1Uu7dXKdxaG qgBA== 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 a10-20020a631a4a000000b004fbd563f23fsi20249938pgm.166.2023.03.23.20.04.58; Thu, 23 Mar 2023 20:05:10 -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; 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 S229752AbjCXCyT (ORCPT + 99 others); Thu, 23 Mar 2023 22:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjCXCyR (ORCPT ); Thu, 23 Mar 2023 22:54:17 -0400 Received: from mail.nfschina.com (unknown [42.101.60.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91BB293E3 for ; Thu, 23 Mar 2023 19:54:12 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 86E3C1A00888; Fri, 24 Mar 2023 10:54:16 +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 gD0FfV6nSDOI; Fri, 24 Mar 2023 10:54:15 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 96B141A00815; Fri, 24 Mar 2023 10:54:15 +0800 (CST) From: Li kunyu To: richard.henderson@linaro.org, ink@jurassic.park.msu.ru, mattst88@gmail.com, aurxenon@lunos.org Cc: linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] alpha: kernel: module: Adding branch statements after allocating memory for kmalloc Date: Sun, 26 Mar 2023 03:25:30 +0800 Message-Id: <20230325192530.3298-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=3.8 required=5.0 tests=DATE_IN_FUTURE_24_48, RCVD_IN_VALIDITY_RPBL,RDNS_NONE,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** 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?1761216677747033854?= X-GMAIL-MSGID: =?utf-8?q?1761216677747033854?= After looking at the process_reloc_for_got function and where it is called, I decided to use a branch statement to increase the robustness of the pointer g. If pointer g allocation fails, when 'chains [i]. next' is executed, it can avoid crashes caused by wild pointers. Signed-off-by: Li kunyu --- arch/alpha/kernel/module.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c index cbefa5a77384..8c97f10347a7 100644 --- a/arch/alpha/kernel/module.c +++ b/arch/alpha/kernel/module.c @@ -47,11 +47,15 @@ process_reloc_for_got(Elf64_Rela *rela, } g = kmalloc (sizeof (*g), GFP_KERNEL); - g->next = chains[r_sym].next; - g->r_addend = r_addend; - g->got_offset = *poffset; - *poffset += 8; - chains[r_sym].next = g; + if (g) { + g->next = chains[r_sym].next; + g->r_addend = r_addend; + g->got_offset = *poffset; + *poffset += 8; + chains[r_sym].next = g; + } + else + chains[r_sym].next = NULL; found_entry: /* Trick: most of the ELF64_R_TYPE field is unused. There are