Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2666778imi; Mon, 25 Jul 2022 05:04:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4pQO3ILFuAYqmDvrL9g8ORLrzwPMjHFB7Xx997SIp2Lw4SRiIAPKSXeO4qnqESVYE+l2w X-Received: by 2002:a1f:2892:0:b0:375:95c3:e713 with SMTP id o140-20020a1f2892000000b0037595c3e713mr3098047vko.10.1658750680007; Mon, 25 Jul 2022 05:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658750679; cv=none; d=google.com; s=arc-20160816; b=beahSyqeU+S4/fb0nqj1o2vgH6yNWVPokk/ECXK5Z9iOc/gcbL0FiZYthtPjYVm4nc nxdq8Dw3ZmMYwG2exyU/zwbBapyuXy2BLAgTFzIjEVBso+VPTSefybEwWoxj+IkQCS/K i4SvEKUMWuYkScSdopF+JX5pfAHizOrnu5g5yzYqe9JO10BMeMz9wjxkASHkU9tCDdxF X3z5Hjd7O8r7IIfoFjxGAeid+Hzwe5CHTK1FhWAI2o0lun9m7meCQg9HPMHEgAk8wi2H fWrC/nZP1UQFcoLhjco/OruSC3lIBPQlO0CHVET5yBNalaLJA8jUIrAt7VedRta4ngvw jNDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DC8Msj5We1jRi2peyW6hDLuCI7KRsqB8kAb6Afqz75s=; b=A56IjhTRqtQhDHeIJ50tBSEYRZctOmhM7C75/O4u77Xl9FuVXCGg8zEYlLT6e0eD2M Q47DZ9Ib2vws5sAetpE3pIOnQR4PKJQ9NlqI5Q5ldnRGFCE/Cmxl1Yfo+I7mrGKZXQrS zSai1MTOq/uolYSRH04Hx3iubKwd1pTBPpy4EPny7avMxhG74yHF9MY/wDFc393qAhJM 0rmu/rapd5rdrvMuG9cx5Iov/bFpgj5sHyxt/FPwJoexuDRJks+zrfVkY4AN8tJFfqW4 AhimSbYhAVABNgXtkfxUkeN6nZEZctFpjvqkZ0Xo7uKqtlH2Dajbko8UChbU93aclnUt OdHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="X5HW/Oum"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i1-20020a672201000000b0034bb8362b00si1310438vsi.647.2022.07.25.05.04.20; Mon, 25 Jul 2022 05:04:39 -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=@kernel.org header.s=k20201202 header.b="X5HW/Oum"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232514AbiGYLJX (ORCPT + 99 others); Mon, 25 Jul 2022 07:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiGYLJV (ORCPT ); Mon, 25 Jul 2022 07:09:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3979E1208C; Mon, 25 Jul 2022 04:09:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DC6CFB80D94; Mon, 25 Jul 2022 11:09:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E78AC341C6; Mon, 25 Jul 2022 11:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658747357; bh=7s8wumHi7uCMnB5Lfg2/f4FNxAw+WQi+UNCXFTORKmI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X5HW/OumUS2GR5HxkR84tIUnt8t6ElnWNHP/sdYrpmK0Wl0mNrHtt7gCjUIw0kN0i VbjfGzLg3dw7Y3QtGhgj1tToo/belxF6WRPii2diHisgKlL43xL2aUV+Z4xZN6k0jH U6FBEYmDJGLxJJVURlaq+6MyDT+0SB8n8s2nFu+r4E7EqThHZxJode0lJKmzDhtdqq ATI4HxVPH9RgYOTPZpP1XuYZ8ctXrWl2HluiFepcc8Cj7pl0dzav47GXGw20m5iFxT MIq/UNz+o8Qjkfr6tZY3mBRe6FSIpuccqEHauNOpszD2L8gEQbWK0hiZjdJqtymh0N DsmB4S0At0O5A== Date: Mon, 25 Jul 2022 13:09:11 +0200 From: Robert Richter To: Borislav Petkov Cc: Toshi Kani , mchehab@kernel.org, elliott@hpe.com, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] EDAC/ghes: Fix buffer overflow in ghes_edac_register() Message-ID: References: <20220721180503.896050-1-toshi.kani@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On 25.07.22 12:45:24, Robert Richter wrote: > On 25.07.22 12:14:21, Borislav Petkov wrote: > > On Mon, Jul 25, 2022 at 11:53:06AM +0200, Robert Richter wrote: > > > The dimm->label buffer must be pre-initialized zero. This broke with: > > > > > > b9cae27728d1 EDAC/ghes: Scan the system once on driver init > > > > > > since krealloc/krealloc_array() does not zero out the new allocated > > > buffer for struct dimm_info in enumerate_dimms(). This uninitialized > > > broken struct is then copied in ghes_edac_register() to the final > > > dimm_info destination. Originally, before b9cae27728d1, the struct was > > > zero initialized with kzalloc'ed by edac_mc_alloc() and directly used. > > > Now, that a copy is created first, this copy must be also zero > > > initialized. > > > > > > IMO this is the proper fix: > > > > Maybe, but this needs fixing too: > > > > /* both strings must be non-zero */ > > if (bank && *bank && device && *device) > > > > Obviously one of those strings are zero coming from that BIOS... I see now, what you mean here, may be change this: snprintf(dimm->label, sizeof(dimm->label), "%s %s", (bank && *bank) ? bank : "N/A", (device && *device) ? device : "N/A"); to: snprintf(dimm->label, sizeof(dimm->label), "%s%s%s", (bank && *bank) ? bank : "", (bank && device) ? " " : "", (device && *device) ? device : ""); It keeps the default assignment from edac_mc_alloc_dimms() but changes we label if one of bank or device is given. -Robert > > But the label is pre-initialized in edac_mc_alloc_dimms(): > > p = dimm->label; > n = snprintf(p, len, "mc#%u", mci->mc_idx); > > You check if the label is emtpy when copying it in > ghes_edac_register(): > > if (strlen(src->label)) > memcpy(dst->label, src->label, sizeof(src->label)); > > So if there is nothing that comes from the bios, this default label > string from edac_mc_alloc_dimms() will be used. > > If you write "N/A" to the label instead, the sysfs dimm_label values > wont be unique any longer between dimms, which might break existing > applications. > > -Robert > > > > > -- > > Regards/Gruss, > > Boris. > > > > https://people.kernel.org/tglx/notes-about-netiquette