Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp97241lqp; Thu, 4 Apr 2024 08:02:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW0XVH+rEU5HX2jZWQVvb6Q44TosFTOwCTsqIjz8vt1nKqQXAhPJFvHTuVEBi7A0wrDI+gwgsWS/OjkbLzX4+O63/uvoTNwWlbIuLxvPg== X-Google-Smtp-Source: AGHT+IFr4OVeiXmV8nv3xCJYSG+ByhkbCGKjKMgbEjfbyuFZq3qSdfFCLMxGTTAAzurAIiBlPanK X-Received: by 2002:a17:906:f819:b0:a4e:2e25:75b5 with SMTP id kh25-20020a170906f81900b00a4e2e2575b5mr1749341ejb.55.1712242926778; Thu, 04 Apr 2024 08:02:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712242926; cv=pass; d=google.com; s=arc-20160816; b=NZUIRdQvz3HvAPwpz0rFgx7J9o0XtQaEWsd4LrxIowTZGjKrfZc9cDqJ8wsxavY3KE gd+/25Y9UBbz1r0MpjukPtB9R8qEVx6Rwjs7PTmp+g0HN/3HrcRAfd+wu+AiEopZlhF0 D50Q9d5Ksa6rvpvz/CT0Ov2lUzNHvbb932fpH+HzhDQR1veb+M6JyhEQxbCdwbIv6tWi UMFWnGQ7PDLnbZBBSK8uT34nIJIsTCfuOLQDd5dlscdll84q7Hy4bfOvUsA8v+5jA9t0 k0K/s6eN1wBN29gSdNk1tKgk9rhiz8EuB4tM4NnYPoTc5T83URvcCJMp3dj+pG0J2pST dg9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=/C/fFIaOSsCUPyra/cymX2LoLnbF9LWbupiirgNC49I=; fh=IFbulrbVe4HyD1iXhnpHxvv/g7qS5mGbM63rRhNgSl4=; b=VBu/NJhZBu6hTfilsaEj+KzAvSiakvH3QUvQFtkRAGjFEuKtM6vjS5/xRyTHC1zV4z SUguLFdcCa6WJsK+TqSidyv8Z+cjXH+RIDV6q4tJf5UtPa+tfsGe51xwYLgfAuzRfx4O /Zk/F42TOkT90qjQlp322/XkqS2Budr8EnaDX3aiRYhGNcAQgvc7FHANF/xCjKqCT0DM g8Nw7yZUgaiOddT8oWxtUGusclUiBNtpvr2QPjKyANUTQAtqUMh0KNo+UAD72x3+kSda UlQp8YOKHhXFVyfaeblsjGygXGpVULLSdx/jL8oqQb+7G+y8lB/PZQoBNUK+6If1Wh8z WhXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O849EgRl; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131666-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131666-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cs12-20020a170906dc8c00b00a4e595d5cc8si5386676ejc.791.2024.04.04.08.02.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 08:02:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131666-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O849EgRl; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131666-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131666-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 81FA21F28E4E for ; Thu, 4 Apr 2024 15:02:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 283F26E615; Thu, 4 Apr 2024 15:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="O849EgRl" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D41E21C2A1; Thu, 4 Apr 2024 15:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712242843; cv=none; b=fV7gdlVtvkKOI31MSL7DM4m21aqMiL3ufXE0QO0Nd35wrEc3es3c3UXvLkWQEF6JRLrvv4RAhPFgDrlnDH6NFzabFv+1l2ONsN5MTZtLkfcUacl/wI96y2yX7e9HaLJwjTrD0xeuCq5LASWqoJ6euJA9naN4M+ZI5Jm8jeJWy7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712242843; c=relaxed/simple; bh=k0VeJYbpn/TShgzYqdD2a34SZlW9LgfGRcTUiFmDZpg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cMQ9fP8BibXJM8BbKrKLXn4ZossHTYtyIxage2zWNovppJJpOptE2udlXFLmW0TipZb3uUNRxhbNY369njcOLCAjRISb+Ix7G3uIBp2w22bT5ExJoQwfquifMj8eTqAvOBmksgKTszyQc1QvjK58QNxTjzbhDxW8VrmHRTVRZIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=O849EgRl; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712242842; x=1743778842; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=k0VeJYbpn/TShgzYqdD2a34SZlW9LgfGRcTUiFmDZpg=; b=O849EgRlT3B2Zfy6hyTh+yMgUlPyzGLPyEHFn8+ZEELo2+N7Axwp760U DGdhKOvNf2EGCOzUuy6FsJHPHbzRLHCLHSGJYq+AeW0y5xDXda1Gu55z8 PXvdiF7+aVcUqREMdZ8vSCwoKowcTk2FNqKcc7ET06B2mBfgvxGjzM0t/ 9p030X40HU/zsIge/z9BDk1IbooLO/HwOgSw8wkNpf30heMan2gxU0nIO 14/XFOUkKdTtqueVHR8uj6ihRyAD+ukpx0OFgoHQMgyUMMT+QrwPTGqZz vHS1pWGCcLmW3F0DiSZY0/Lu6LLSVG2DFAHu7jimAga+TUnDaRtQPKL2D A==; X-CSE-ConnectionGUID: Xw7L3KaYT6qE5fb+DpLugQ== X-CSE-MsgGUID: Ho72HPApTxm6FQ8oLsYZPQ== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="7766868" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="7766868" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 08:00:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="937086705" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="937086705" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 04 Apr 2024 08:00:38 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 28DED812; Thu, 4 Apr 2024 18:00:37 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Jiri Slaby , Yicong Yang , Tony Lindgren , Andy Shevchenko , kernel test robot Subject: [PATCH v1 1/1] serial: core: Clearing the circular buffer before NULLifying it Date: Thu, 4 Apr 2024 17:59:26 +0300 Message-ID: <20240404150034.41648-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The circular buffer is NULLified in uart_tty_port_shutdown() under the spin lock. However, the PM or other timer based callbacks may still trigger after this event without knowning that buffer pointer is not valid. Since the serial code is a bit inconsistent in checking the buffer state (some rely on the head-tail positions, some on the buffer pointer), it's better to have both aligned, i.e. buffer pointer to be NULL and head-tail possitions to be the same, meaning it's empty. This will prevent asynchronous calls to dereference NULL pointer as reported recently in 8250 case: BUG: kernel NULL pointer dereference, address: 00000cf5 Workqueue: pm pm_runtime_work EIP: serial8250_tx_chars (drivers/tty/serial/8250/8250_port.c:1809) ... ? serial8250_tx_chars (drivers/tty/serial/8250/8250_port.c:1809) __start_tx (drivers/tty/serial/8250/8250_port.c:1551) serial8250_start_tx (drivers/tty/serial/8250/8250_port.c:1654) serial_port_runtime_suspend (include/linux/serial_core.h:667 drivers/tty/serial/serial_port.c:63) __rpm_callback (drivers/base/power/runtime.c:393) ? serial_port_remove (drivers/tty/serial/serial_port.c:50) rpm_suspend (drivers/base/power/runtime.c:447) The proposed change will prevent ->start_tx() to be called during suspend on shut down port. Fixes: 43066e32227e ("serial: port: Don't suspend if the port is still busy") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202404031607.2e92eebe-lkp@intel.com Signed-off-by: Andy Shevchenko --- I have got into the very similar issue while working on max3100 driver. I haven't checked the 8250 case, but for mine the culprit is the same and this patch fixes it. Hence I assume it will fix the 8250 case as well. drivers/tty/serial/serial_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index a005fc06a077..ba3a674a8bbf 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1788,6 +1788,7 @@ static void uart_tty_port_shutdown(struct tty_port *port) * Free the transmit buffer. */ uart_port_lock_irq(uport); + uart_circ_clear(&state->xmit); buf = state->xmit.buf; state->xmit.buf = NULL; uart_port_unlock_irq(uport); -- 2.43.0.rc1.1.gbec44491f096