Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp496687imw; Fri, 15 Jul 2022 07:20:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u/ZadzmElqWdEck/pX4og8Rr5MQwQKwxQJUPhkhUtoCBalDmueQYspYY7RiUByWUE0aTd0 X-Received: by 2002:a63:504c:0:b0:419:d02e:f42a with SMTP id q12-20020a63504c000000b00419d02ef42amr4855660pgl.566.1657894825511; Fri, 15 Jul 2022 07:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657894825; cv=none; d=google.com; s=arc-20160816; b=Rad3OJPZNXvQgORshv2rIVXdF7AVRg1uZr3IR6S0nOwxrruqh4bATho9Fi8G3Gw0nW NZwY/xukI5BUQh6RoXf5nuEvght/TjVisdheteZDNI5SRJGvWiKxxZDVoWrTOZ+mJMdQ 2YSTiFE/C+JASlx2xZxWMx3JVRZspFwajb4sPmSW4y7dAlvM7nlHF2k7nVkDHtznmZm7 P3h9gcK9LyUMVlP3DwCXp6h/v+viNABM5i8gamXEdsFkunP6RJt01gaHYSKUH/IJAmL2 IlFCC96p31eZMLfzurKjQlFIk7XcuQoz7/OqUdJ6ctODJrT6Nm0OdFkFqMDnDVEsCuDj hzvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ztCghPPoUnOpsLVNELkPxJrcEN341WBw/1cZkMFiYWs=; b=dYZGjqQPpKHiCvwai59+b9HYwpy9wfmaPrESqG/ZXwMG5s2WGWPzQvfMaLHgH9TrVo EYnUCZbecbDkWpAS1RMH5z2BUNbVId/1v2yc3wjhZIyD8pXWP++DxQrPO+0DP3Mou/hf AN0zioMoZD6D50r3aSbmix2meCb7TiJALHE3e0SH4IaAARKueZfSolHUpu8c9UGzvU9k AuYhtAq+TwwL+Z0/PkMSjE/E6jVd3ViYi8fOLY0J1kjI4tRCEV6U0CMuHK7ThBPsq7hC mApTtcrQXdxdMmroXD+hOhYTQH1YIdaO0UZisw1Dsp6MViIWkyYHpjm/pBaSeCeNreYR aR8Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h31-20020a63211f000000b0041288737bc6si4529852pgh.797.2022.07.15.07.20.07; Fri, 15 Jul 2022 07:20:25 -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 S235129AbiGOODd (ORCPT + 99 others); Fri, 15 Jul 2022 10:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234025AbiGOODW (ORCPT ); Fri, 15 Jul 2022 10:03:22 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C478F26AC1 for ; Fri, 15 Jul 2022 07:03:20 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by laurent.telenet-ops.be with bizsmtp id vS3J2700R4C55Sk01S3JMp; Fri, 15 Jul 2022 16:03:18 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1oCLuY-003gpc-7b; Fri, 15 Jul 2022 16:03:18 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1oCLuX-00EDej-Nj; Fri, 15 Jul 2022 16:03:17 +0200 From: Geert Uytterhoeven To: Pantelis Antoniou , Frank Rowand , Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/2] of: overlay: Move devicetree_corrupt() check up Date: Fri, 15 Jul 2022 16:03:14 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 There is no point in doing several preparatory steps in of_overlay_fdt_apply(), only to see of_overlay_apply() return early because of a corrupt device tree. Move the check for a corrupt device tree from of_overlay_apply() to of_overlay_fdt_apply(), to check for this as early as possible. Signed-off-by: Geert Uytterhoeven --- drivers/of/overlay.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 4044ddcb02c60a58..84a8d402009cb3b2 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -903,12 +903,6 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) { int ret = 0, ret_revert, ret_tmp; - if (devicetree_corrupt()) { - pr_err("devicetree state suspect, refuse to apply overlay\n"); - ret = -EBUSY; - goto out; - } - ret = of_resolve_phandles(ovcs->overlay_root); if (ret) goto out; @@ -983,6 +977,11 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, *ret_ovcs_id = 0; + if (devicetree_corrupt()) { + pr_err("devicetree state suspect, refuse to apply overlay\n"); + return -EBUSY; + } + if (overlay_fdt_size < sizeof(struct fdt_header) || fdt_check_header(overlay_fdt)) { pr_err("Invalid overlay_fdt header\n"); -- 2.25.1