From patchwork Fri Oct 25 13:31:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2002239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XZkGc6S1Sz1xxK for ; Sat, 26 Oct 2024 00:32:08 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t4KQ5-0006yK-6p; Fri, 25 Oct 2024 13:32:01 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t4KQ4-0006x3-2Z for kernel-team@lists.ubuntu.com; Fri, 25 Oct 2024 13:32:00 +0000 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 7213D3FA4D for ; Fri, 25 Oct 2024 13:31:58 +0000 (UTC) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-71e49ae1172so2132817b3a.2 for ; Fri, 25 Oct 2024 06:31:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729863117; x=1730467917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kyWYdulo+5Wnop/otlAvZ9hUIt7udwwe5mn2YjrAI3I=; b=St/h8oWxBnoivcBR+fvLPFakcGTTFheXs9MppAxmjPei9yqBeuB8jzBkWfsPYWSztc A2U8SyIi35j8X8euBBEnSYEGLmYRmyHI8S90TB9/dnRb22T8gppsY66CbjB8d+EK+DoJ sfEZvEwWbVlOYOKe9n0XJj59nGC9vseT/jltd3079/MyqxvF3d++jrTeGHpy7tTgS+up nrQiAXUaLUg2zvxJy5x2S9wXY60Da8fd0nVmp1mA0xyucSYbNWx1MtcGh1V2YJSkqO/V pizADI9MczcRGBaGvc98JvXAQjTrA+URXT+w7dc31PJPGUoV+KXRLpe7APpKaKFZdPDG mECw== X-Gm-Message-State: AOJu0YwdOyerW7eTatwGY3rHN4lwdnGid3ImXUURrjROwEhcZnTbbNsS Zlt0JnhlHxmmmdl8EdnMRvtYEKJVzQ4U28BMidPA9EQKBfqdzxniCJEx4U1q0AagrpfuCo5gf60 gpY7tqg0gtM3S40rP445K0tLZlwHw9eIySW0piqU6Jrd9B5DyVjE4O6PQd41YjwiwS6oGML6qAf CyRV+NX4TRhg== X-Received: by 2002:a05:6a20:d04e:b0:1d5:1354:5256 with SMTP id adf61e73a8af0-1d989cf91c2mr6453403637.39.1729863116598; Fri, 25 Oct 2024 06:31:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFz+XZa+lnVncUAAAAanbCUxZQo3gkFh173XEckb14mGdvdDAynu3aC/Lp0s60joPhd3hh60w== X-Received: by 2002:a05:6a20:d04e:b0:1d5:1354:5256 with SMTP id adf61e73a8af0-1d989cf91c2mr6453359637.39.1729863116138; Fri, 25 Oct 2024 06:31:56 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:9b52:57a4:8bdb:99d3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057921983sm1077883b3a.10.2024.10.25.06.31.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 06:31:55 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 2/3] ftrace: Return the first found result in lookup_rec() Date: Fri, 25 Oct 2024 22:31:05 +0900 Message-ID: <20241025133110.2839066-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241025133110.2839066-1-koichiro.den@canonical.com> References: <20241025133110.2839066-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Artem Savkov It appears that ip ranges can overlap so. In that case lookup_rec() returns whatever results it got last even if it found nothing in last searched page. This breaks an obscure livepatch late module patching usecase: - load livepatch - load the patched module - unload livepatch - try to load livepatch again To fix this return from lookup_rec() as soon as it found the record containing searched-for ip. This used to be this way prior lookup_rec() introduction. Link: http://lkml.kernel.org/r/20200306174317.21699-1-asavkov@redhat.com Cc: stable@vger.kernel.org Fixes: 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()") Signed-off-by: Artem Savkov Signed-off-by: Steven Rostedt (VMware) (cherry picked from commit d9815bff6b379ff46981bea9dfeb146081eab314) [koichiroden: Follow-up fix for the preceding prerequisite commit] CVE-2024-38588 Signed-off-by: Koichiro Den --- kernel/trace/ftrace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index d9992fef7287..e40bbd18bc99 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1552,6 +1552,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) rec = bsearch(&key, pg->records, pg->index, sizeof(struct dyn_ftrace), ftrace_cmp_recs); + if (rec) + break; } return rec; }