Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3460524pxf; Mon, 29 Mar 2021 02:53:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvP6p8zctyNex05PDQXb7Op/RDYqT71Xh3YmRa+l7duMREsvUVd3PMHMPJVHdXAob6nr5q X-Received: by 2002:a05:6402:3493:: with SMTP id v19mr28568797edc.355.1617011614110; Mon, 29 Mar 2021 02:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617011614; cv=none; d=google.com; s=arc-20160816; b=Fvv5K/PajhKk7anooE123ZoeL4ePBKWDRsmygkpFJU+OWD35zNMiRGeT6FFKTrfJQm TA1EvZXgSJHIXqMP3sBjqsalU1z0yEIgw8Fnp4MDfuuhn6bX958zkPlnKiU2qzKkbkQG +lRlrN9JElgpIN5onn/g4wQelsLolIb16mQzhmJwsQ/tjud2hbIM2tg6+EoVOd9yLL4p F8JarPhxUjOXnLM4NhAlAchLy1E65mtzp91v6pWsU5Qp3TTWBaaIKjOo9farUPsxFiKS QnOLkoUhsYKvnCZpsj612NuU+xYn02xZfLub+7ddij43cYbu5vXmVqoFv3N7EnaCzdXD 7osQ== 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=aYEdMBCzGj3/8j/gJJgcM9klolN7CguoiajgVzbStSg=; b=asELnvTs6yMKndC3zZgc7K/oMS8ClOrtLSYt3jEnjXR1iv/tAleIqyO4vZyryDfjUj 5LFOOX6eh0WYO/oWiZdY/euGa4JQ7dP+7ohz5t03s6/OIEBlubBBFPZVDkFZtSYpIgyP gVAfr7y1G89zvGAsTmC69IFaCK7iXUAXTIFwyCWRx6QCujUobnlbFzIBkH0yg+c13U3x pnjXet9KGNokfb/xk6grgFGZzGR5kZz+u2/nY5wdyzLkqQ6CniGRo5GkvjgPRdjLokKw OEhRI6wjLS1N2P82jMff+zjwY99Beb64vN2KKhmX0Iqja1mGrut3pvXZKJe6IBQfNvM4 +TPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a21si14000313edn.317.2021.03.29.02.53.12; Mon, 29 Mar 2021 02:53:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231854AbhC2Jt7 (ORCPT + 99 others); Mon, 29 Mar 2021 05:49:59 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:40070 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231594AbhC2Jtb (ORCPT ); Mon, 29 Mar 2021 05:49:31 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=yang.lee@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UThbzQ9_1617011366; Received: from j63c13417.sqa.eu95.tbsite.net(mailfrom:yang.lee@linux.alibaba.com fp:SMTPD_---0UThbzQ9_1617011366) by smtp.aliyun-inc.com(127.0.0.1); Mon, 29 Mar 2021 17:49:26 +0800 From: Yang Li To: tony.luck@intel.com Cc: bp@alien8.de, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, hpa@zytor.com, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Li Subject: [PATCH] x86/mce/dev-mcelog: Fix potential memory access error Date: Mon, 29 Mar 2021 17:49:20 +0800 Message-Id: <1617011360-102531-1-git-send-email-yang.lee@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using set_bit() to set a bit in an integer is not a good idea, since the function expects an unsigned long as argument, which can be 64bit wide. Coverity reports this problem as High:Out-of-bounds access(INCOMPATIBLE_CAST) CWE119: Out-of-bounds access to a scalar Pointer "&mcelog->flags" points to an object whose effective type is "unsigned int" (32 bits, unsigned) but is dereferenced as a wider "unsigned long" (64 bits, unsigned). This may lead to memory corruption. /home/heyuan.shy/git-repo/linux/arch/x86/kernel/cpu/mce/dev-mcelog.c: dev_mce_log Just use BIT instead. Reported-by: Abaci Robot Signed-off-by: Yang Li --- arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c index 100fbee..fd7b1b4 100644 --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c @@ -51,7 +51,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, * earlier errors are the more interesting ones: */ if (entry >= mcelog->len) { - set_bit(MCE_OVERFLOW, (unsigned long *)&mcelog->flags); + mcelog->flags |= BIT(MCE_OVERFLOW); goto unlock; } -- 1.8.3.1