Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3321477rwo; Fri, 4 Aug 2023 03:06:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFj9z7/LCKsoEoXcxmhtpufT9ViJKjqFvjVHaMVeypJPqoJcUh8aV2I8Zrx71BVrMeUc71N X-Received: by 2002:a17:90a:4f0d:b0:263:f5fa:cf1b with SMTP id p13-20020a17090a4f0d00b00263f5facf1bmr976971pjh.30.1691143563437; Fri, 04 Aug 2023 03:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691143563; cv=none; d=google.com; s=arc-20160816; b=z4Z3QU2oHvfMD87fFox8PNkuCqKOh6B+cG3FpQ0A7PKVmAA4cBNcNOf6y7tpIG7X7o nHcSkEJ9qPcLTPFtkVIXKI3bQUh213OGz685BOAAAdBwNIivWaPQNO/cSko06GctLtZS q0elsPFskug+EvHE8McIfPfB9t6HycnlmWEwTW3bvsEPkCNbNc6pE3mnuc6u4rHENdJC A6STScFZxspfYAb13Cx6yDhuVZO0W63CBxVdXSHXcRBOaDwkubq6j48YJ08erTb8oAyO xJgFvYmE8W5yD1uNKyN6gSwhFiheYoNMvuDrddBUzA3Gq1kvBqu6IUBa9h4zv/xKx3CH GAGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7sTwnH4sXUXtcKXQVId2GYx+QeFJgqq/fjklOp/tKBE=; fh=FINjpb9ACI2foIp5/jhNw0Cl9abhxcoEZebOZcf3flA=; b=dhEzGP3FJf/9INmyPv/wLCq2+k8+r9sx3GhesrXy3vSCqZGnb6ey7EuRecdl4gAUJ5 z4IQzBQozzbnhIoXyXynu/sbfDF744gq3Kg1gze5TjuRIdTo6soPm5CShRRawBmAp+ID VFq1X76tAOufoz02sO/F54WTVOzcvZF7xdkjnb+lM6goPRVjdKGx6E3qXz98CecYJSEc FgQx2fC+fZhFhQda9MbVKUp1QDe/mAx4T4pWZ6/d067S2PTgdgOyllEoW3h1r4BhWBVx 7GeUtjcefH8Wm2LI2MvfgJewkHERKAOeD+MnlSDzRFaIF7n7FH0E7O1g4C/TpPn+GnDJ lqRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mRMW2zm1; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gi7-20020a17090b110700b00262e5a82047si1634265pjb.44.2023.08.04.03.05.51; Fri, 04 Aug 2023 03:06:03 -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=@gmail.com header.s=20221208 header.b=mRMW2zm1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbjHDJD6 (ORCPT + 99 others); Fri, 4 Aug 2023 05:03:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbjHDJDd (ORCPT ); Fri, 4 Aug 2023 05:03:33 -0400 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D0CE4C28; Fri, 4 Aug 2023 01:59:19 -0700 (PDT) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-56cc3453e31so1199888eaf.1; Fri, 04 Aug 2023 01:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691139558; x=1691744358; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7sTwnH4sXUXtcKXQVId2GYx+QeFJgqq/fjklOp/tKBE=; b=mRMW2zm1R3UoTZXU+VKQTRQxtD3PPBxQkRCYagjaV1YoRq4Z+1p758Xoo4FcuHCSwU i1p5ibt2wSBPE/texY/ooxsUU29II2nNLlmO4SmmFjz/8LNtPcxOa5Z9/vFDJb+wLmNq YMnyfG2UWstxefSKe1oBoIAia/jTYzFVgdVz71VSvQwlbpLz6HATn1/44lpsl1hf4PVY Tub53w3GDGj+mfJyJHkxkOVasIt45n2cI937s4PzYu/RVVY14AcX5bFK7AI7U3oXRLal Mz7OkeDyjABmPZBusom4rdulnpVuGFhmGrs+usxq+jE4/3P0OriBEg3kwrV3SvgY89xh UEPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691139558; x=1691744358; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7sTwnH4sXUXtcKXQVId2GYx+QeFJgqq/fjklOp/tKBE=; b=GeBRJ90Bo2ClwJEuLNIEEJbjSuugNRXcMPrymrPiDab6EXfFDrWrcoh2qLf3OV2Ucz yQXwZX/Pk1c8QwFs5OCWpnoMUA7V2BNFnaIXFeqmSZ0QhNtFPqi5JVVOgXa+cCeHc9Rv Ukcp3gQkif8FWz6jDBf3heQRJEbKuUL6LPVhvRxeRJGaKke1i+gAOvHgTXqR1vPtSOgQ g55C+DRyC3KotSfslyGI4JwjXfcWYxs+g4dkA7aMHCqCo/E+vMVCUjhBAziukvcylR5V YW4X9jmYaZ4NNDie+5dj6dsOzyxVt1g8NX6/Z3iWwkwCPAw0E/lXl3cKkuO6Y02e8WPO BSsA== X-Gm-Message-State: AOJu0Yyb9hkXR0bI4KrCf4O6jeb78cSPlC7H0qKGfdt+8ATCLvV5Svfm A2d6M2qknOwtvacQtlQw5aM/GMPDsiHn9xY5R70= X-Received: by 2002:a4a:9243:0:b0:56c:8c66:cea6 with SMTP id g3-20020a4a9243000000b0056c8c66cea6mr1185978ooh.1.1691139558429; Fri, 04 Aug 2023 01:59:18 -0700 (PDT) MIME-Version: 1.0 References: <20230801060432.1307717-1-yunlong.xing@unisoc.com> <202308040103.1514A8C3CB@keescook> In-Reply-To: <202308040103.1514A8C3CB@keescook> From: yunlong xing Date: Fri, 4 Aug 2023 16:59:07 +0800 Message-ID: Subject: Re: [PATCH 1/1] pstore/ram: Check member of buffers during the initialization phase of the pstore To: Kees Cook Cc: Yunlong Xing , tony.luck@intel.com, gpiccoli@igalia.com, joel@joelfernandes.org, enlin.mu@unisoc.com, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, enlinmu@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,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 Fri, Aug 4, 2023 at 4:10=E2=80=AFPM Kees Cook wr= ote: > > On Tue, Aug 01, 2023 at 02:04:32PM +0800, Yunlong Xing wrote: > > From: Enlin Mu > > > > The commit 30696378f68a("pstore/ram: Do not treat empty buffers as vali= d") > > would introduce the following issue: > > > > When finding the buffer_size is zero, it would return directly.However,= at > > the same time, if the buffer's start is a illegal value, the others wou= ld > > panic if access the buffer. > > Which "others" do you mean? About =E2=80=9Cothers", You can refer to the following panic call stack: sysdump_panic_event+0x720/0xd38 atomic_notifier_call_chain+0x58/0xc0 panic+0x1c4/0x6e4 die+0x3c0/0x428 bug_handler+0x4c/0x9c brk_handler+0x98/0x14c do_debug_exception+0x114/0x2ec el1_dbg+0x18/0xbc usercopy_abort+0x90/0x94 __check_object_size+0x17c/0x2c4 persistent_ram_update_user+0x50/0x220 persistent_ram_write_user+0x354/0x428 ramoops_pstore_write_user+0x34/0x50 write_pmsg+0x14c/0x26c do_iter_write+0x1cc/0x2cc vfs_writev+0xf4/0x168 do_writev+0xa4/0x200 __arm64_sys_writev+0x20/0x2c el0_svc_common+0xc8/0x22c el0_svc_handler+0x1c/0x28 el0_svc+0x8/0x100 > > > To avoid these happenning, check if the members are legal during the > > initialization phase of the pstore. > > > > Fixes: 30696378f68a ("pstore/ram: Do not treat empty buffers as valid") > > Cc: stable@vger.kernel.org > > Signed-off-by: Enlin Mu > > --- > > fs/pstore/ram_core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c > > index 85aaf0fc6d7d..eb6df190d752 100644 > > --- a/fs/pstore/ram_core.c > > +++ b/fs/pstore/ram_core.c > > @@ -519,7 +519,7 @@ static int persistent_ram_post_init(struct persiste= nt_ram_zone *prz, u32 sig, > > sig ^=3D PERSISTENT_RAM_SIG; > > > > if (prz->buffer->sig =3D=3D sig) { > > - if (buffer_size(prz) =3D=3D 0) { > > + if (buffer_size(prz) =3D=3D 0 && buffer_start(prz) =3D=3D= 0) { > > pr_debug("found existing empty buffer\n"); > > return 0; > > } > > And in the case of "buffer_size(prz) =3D=3D 0" but "buffer_start(prz) != =3D 0", > this will be caught by: > > if (buffer_size(prz) > prz->buffer_size || > buffer_start(prz) > buffer_size(prz)) { > pr_info("found existing invalid buffer, size %zu,= start %zu\n", > buffer_size(prz), buffer_start(prz)); > zap =3D true; > } > > i.e. it will be detected and zapped back to a sane state. No,This code has no chance of execution because there was a return 0 before= it > > That sounds correct to me, though I wonder if reporting it as an > "invalid buffer" is inaccurate? Perhaps we should have a separate case: > > if (buffer_size(prz) =3D=3D 0) { > if (buffer_start(prz) =3D=3D 0) > pr_debug("found existing empty buffer\n")= ; > else { > pr_debug("found existing empty buffer wit= h non-zero start\n"); > zap =3D true; > } > } else if ... > > What do you think? Good, I gree it. For me, it should not return directly while finding the buffer_size is zero, We need Check others case. So does the modification method you mentioned require me to resubmit a patch or do you need to modify and merge it > > -- > Kees Cook