From patchwork Thu Nov 14 16:25:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Bouchinet X-Patchwork-Id: 13875463 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 8C6AF13BADF; Thu, 14 Nov 2024 16:27:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601646; cv=none; b=imkm+tp7JWiPSBn0d8cGPm0mNY4uT5P6kGVQcQHvWJkYNK5YOELUmvjROMH4N1aCnKtDMk1Y/jHFOu2oSZ1EoYC/OLPj/7qjznTWOYOSRFHtD/32eK++FBw2tHf57nDCyLafYCV7Zo/nKceDs5OMdIdPj4A3LTajh9pOcA3SZcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601646; c=relaxed/simple; bh=zTooz16rY3AfF/eTpeq17JpgvY9acOw5qHh3CbP/p3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unpKtqI/zDCtR3t4dg+yavjhys/+N7t6Cf2aQqW6hlJnoluv/8gbW371xvJK02otKy2zUYax5lhYlJUy466zGowfbl3RiZkcdLQWi18NC9YlemHKd4eqzS4Ub+g+ZM3IEXfKWL+cFtXMjwLZOehM3k+nkPIOFTi99QPEs662NpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=clip-os.org; spf=pass smtp.mailfrom=clip-os.org; dkim=pass (2048-bit key) header.d=clip-os.org header.i=@clip-os.org header.b=dNtHYrqO; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=clip-os.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=clip-os.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=clip-os.org header.i=@clip-os.org header.b="dNtHYrqO" Received: by mail.gandi.net (Postfix) with ESMTPSA id 3563A1C0003; Thu, 14 Nov 2024 16:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clip-os.org; s=gm1; t=1731601641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4pkqaS9pZOOkHA59eOasRPM/zB+ZaOpCZ3WyTxPANo=; b=dNtHYrqOnStkonMLIS11J9mLWRRZQX/Kkgd0JktCdBylxRqiw1p0b/ploudVPFrhgpCHxJ PBi8tj0MtSZ37H/X6UbgMNGxT+mcavG+lMffwzOjIMtsQ0lKkvluUPUthHgRAYXMHB1nKp p9qzMJMtI99h3eApzkS3fkZ9MGYnwUFYRt3d/V2lMfiJOWJbVhy9Sb71KrvqifI4y9iiZD zreuossdPqB0bziAOJ7vNPoH0m3OzUVJ4bYuAyNmYDBn8dCkBkZhT743BgohSvz4L/KRRQ FafmgvVaR4GPRTtYbCHn543NEBXPpxsCxwtvppRAO28KDUHyft/DpxC/u91lxQ== From: nicolas.bouchinet@clip-os.org To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: nicolas.bouchinet@clip-os.org, Nicolas Bouchinet , Greg Kroah-Hartman , Jiri Slaby , Alexander Viro , Christian Brauner , Jan Kara , Luis Chamberlain , Kees Cook , Joel Granados , Andrew Morton , Neil Horman , Lin Feng , "Theodore Ts'o" Subject: [PATCH v2 1/3] coredump: Fixes core_pipe_limit sysctl proc_handler Date: Thu, 14 Nov 2024 17:25:50 +0100 Message-ID: <20241114162638.57392-2-nicolas.bouchinet@clip-os.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114162638.57392-1-nicolas.bouchinet@clip-os.org> References: <20241114162638.57392-1-nicolas.bouchinet@clip-os.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: nicolas.bouchinet@clip-os.org From: Nicolas Bouchinet proc_dointvec converts a string to a vector of signed int, which is stored in the unsigned int .data core_pipe_limit. It was thus authorized to write a negative value to core_pipe_limit sysctl which once stored in core_pipe_limit, leads to the signed int dump_count check against core_pipe_limit never be true. The same can be achieved with core_pipe_limit set to INT_MAX. Any negative write or >= to INT_MAX in core_pipe_limit sysctl would hypothetically allow a user to create very high load on the system by running processes that produces a coredump in case the core_pattern sysctl is configured to pipe core files to user space helper. Memory or PID exhaustion should happen before but it anyway breaks the core_pipe_limit semantic This commit fixes this by changing core_pipe_limit sysctl's proc_handler to proc_dointvec_minmax and bound checking between SYSCTL_ZERO and SYSCTL_INT_MAX. Fixes: a293980c2e26 ("exec: let do_coredump() limit the number of concurrent dumps to pipes") Signed-off-by: Nicolas Bouchinet --- Changes since v1: https://lore.kernel.org/all/20241112131357.49582-2-nicolas.bouchinet@clip-os.org/ * Remove test condition as suggested by Lin Feng. --- fs/coredump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/coredump.c b/fs/coredump.c index 7f12ff6ad1d3e..c3a74dd194e69 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -1024,7 +1024,9 @@ static struct ctl_table coredump_sysctls[] = { .data = &core_pipe_limit, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_INT_MAX, }, { .procname = "core_file_note_size_limit", From patchwork Thu Nov 14 16:25:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Bouchinet X-Patchwork-Id: 13875464 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 D1E9D18CBEE; Thu, 14 Nov 2024 16:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601655; cv=none; b=AZJVo464bLBbDG0o99kZHsz4aLOtoq/D9fhM+4u0Sea/dg/gFW7WuTpw0XFjmXpFH8N9aXp7pXhG8m66sLIAiAHZD6x0dL2lS9V6DiMPnTypQCY7jTogehXCSBO/SViaAs8yRmpGKd8wdYOpkPo8ynSxkc/X22HGDdaGXzJqRuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601655; c=relaxed/simple; bh=utsyRUv6zF6lfsiqmmdHqVJJDZtIGR3H0bFdUUXhblA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p0F24h59gSsbNcTvUAhgDKWOCDzjTVpmverK/eHTlUuirrglYVbRlUbs3xxaAacmUkr3ydnvB2ctqiUxIlFdFQBEmdur/Tyztp79fstMTYdCE97eX9zOMKiKJtPIMhxZIiWUUBmKumkdO2ehTX5bwJWvzZhCtUNzNCO2RDpFYMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=clip-os.org; spf=pass smtp.mailfrom=clip-os.org; dkim=pass (2048-bit key) header.d=clip-os.org header.i=@clip-os.org header.b=BqKJmiv0; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=clip-os.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=clip-os.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=clip-os.org header.i=@clip-os.org header.b="BqKJmiv0" Received: by mail.gandi.net (Postfix) with ESMTPSA id C20151C0013; Thu, 14 Nov 2024 16:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clip-os.org; s=gm1; t=1731601651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gAZBTJoDFDDpLWVPcLeTfyoC4pnu7r3w7YRXCDSoHus=; b=BqKJmiv0B11YBe3hQszhxsPByGGuHDD5MYESZEzFWfiG7qm14vePNGtYuGkZVZuNneZHSE SWBJLltnu5xYrjEiEhHj2RhA19P5TlpeprH5ACo1r3mlNUDAUO7yX4HVhtXPP3nmYEBh2o x2Z4xvcHNEl5TD2FlopQ8VV0McElTV62KUm9/5yHR0XEJDNXT5wWkEcasKUeO6UknXbha4 GzOV+9feVIw2CQR3QKZ8GX7Az7xiCD6lSDeyOtx9KZLLXmw9qQUWk2P994PbiUk22QWf6i aaFmYiM2fiX/sMY9H2MjNeTWoMly6d6pc8oRAhSBJJlphAYrH5eyZw2edD01rw== From: nicolas.bouchinet@clip-os.org To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: nicolas.bouchinet@clip-os.org, Nicolas Bouchinet , Greg Kroah-Hartman , Jiri Slaby , Alexander Viro , Christian Brauner , Jan Kara , Luis Chamberlain , Kees Cook , Joel Granados , Andrew Morton , Neil Horman , Lin Feng , "Theodore Ts'o" Subject: [PATCH v2 2/3] sysctl: Fix underflow value setting risk in vm_table Date: Thu, 14 Nov 2024 17:25:51 +0100 Message-ID: <20241114162638.57392-3-nicolas.bouchinet@clip-os.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114162638.57392-1-nicolas.bouchinet@clip-os.org> References: <20241114162638.57392-1-nicolas.bouchinet@clip-os.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: nicolas.bouchinet@clip-os.org From: Nicolas Bouchinet Commit 3b3376f222e3 ("sysctl.c: fix underflow value setting risk in vm_table") fixes underflow value setting risk in vm_table but misses vdso_enabled sysctl. vdso_enabled sysctl is initialized with .extra1 value as SYSCTL_ZERO to avoid negative value writes but the proc_handler is proc_dointvec and not proc_dointvec_minmax and thus do not uses .extra1 and .extra2. The following command thus works : `# echo -1 > /proc/sys/vm/vdso_enabled` This patch properly sets the proc_handler to proc_dointvec_minmax. Fixes: 3b3376f222e3 ("sysctl.c: fix underflow value setting risk in vm_table") Signed-off-by: Nicolas Bouchinet --- kernel/sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 79e6cb1d5c48f..37b1c1a760985 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2194,7 +2194,7 @@ static struct ctl_table vm_table[] = { .maxlen = sizeof(vdso_enabled), #endif .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, #endif From patchwork Thu Nov 14 16:25:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Bouchinet X-Patchwork-Id: 13875465 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 F389C18CBEE; Thu, 14 Nov 2024 16:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601666; cv=none; b=IGr+36MRloHodSixqIDg4NZoqX2ZCc+r8fry+v5tBEIx9A4l7U6lgBckBIVwSLTAHMZJCx2U0BC40BbN8Hohebf9zy2IhhPWJFCQyUKG7ZEzrsTgt1L/w+1Fim9UIJAq7NQxNUY4BJaA/OB98OdwpOBsmcDvdnarxexF0gSFs0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601666; c=relaxed/simple; bh=n5hyX6yMomOaBzphPxzWAbVrcJaUdxbAmwSzohj0OEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gcnIh3qphGqvqtrp+1w0Dojw4CcK9HkO47yfqxxHYTtXd4Y28oEWgIVGyyr8cVBOasEPa4/+iFQSWs2NAiIK5khzLt6Z56f43/b83sws+gmwMEKGxDWCFET3MfHpDR+0a5TzOUdfhLsHSEIL+mN6OKxUpce/J22j7csLV7mRI1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=clip-os.org; spf=pass smtp.mailfrom=clip-os.org; dkim=pass (2048-bit key) header.d=clip-os.org header.i=@clip-os.org header.b=WDyLFrSq; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=clip-os.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=clip-os.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=clip-os.org header.i=@clip-os.org header.b="WDyLFrSq" Received: by mail.gandi.net (Postfix) with ESMTPSA id CDFCB1C0007; Thu, 14 Nov 2024 16:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clip-os.org; s=gm1; t=1731601662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8TPoafWSqHQ3L6VZWGol10eaPnstQLMyyt96RSAYCQ0=; b=WDyLFrSqJmEjmOtTCzCChcWaYROO0VuqcA411o2X0wx2J9FXRoFGB7goiSmWzBFiVEA1g0 oXXIU+c1WAgAY9JM43ch9OzSyVFH3u8oH8rI+otcf1WdbdGyN0ZBGxWkHolgpKHlFjcdQ6 MwHXRKJxFWh53bD6JZ6y40K6jT/XAKFDVu25rr+OB0BhGLwmRAAd2hanWh4NdoT/IKGqvd qo/6xGkCGP40377itTRTYuLR8xNRFtLlggO3o2InkA8t0QEurKPd6DWOAyyuysA0xiDT92 X9gGRoCg4oJ/QMKFdNx9g83FJ5ey4SxtFyY7+3wULcImuQ2OUiKbVIXdjzBwrg== From: nicolas.bouchinet@clip-os.org To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: nicolas.bouchinet@clip-os.org, Nicolas Bouchinet , Greg Kroah-Hartman , Jiri Slaby , Alexander Viro , Christian Brauner , Jan Kara , Luis Chamberlain , Kees Cook , Joel Granados , Andrew Morton , Neil Horman , Lin Feng , "Theodore Ts'o" Subject: [PATCH v2 3/3] tty: ldsic: fix tty_ldisc_autoload sysctl's proc_handler Date: Thu, 14 Nov 2024 17:25:52 +0100 Message-ID: <20241114162638.57392-4-nicolas.bouchinet@clip-os.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114162638.57392-1-nicolas.bouchinet@clip-os.org> References: <20241114162638.57392-1-nicolas.bouchinet@clip-os.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: nicolas.bouchinet@clip-os.org From: Nicolas Bouchinet Commit 7c0cca7c847e ("tty: ldisc: add sysctl to prevent autoloading of ldiscs") introduces the tty_ldisc_autoload sysctl with the wrong proc_handler. .extra1 and .extra2 parameters are set to avoid other values thant SYSCTL_ZERO or SYSCTL_ONE to be set but proc_dointvec do not uses them. This commit fixes this by using proc_dointvec_minmax instead of proc_dointvec. Fixes: 7c0cca7c847e ("tty: ldisc: add sysctl to prevent autoloading of ldiscs") Signed-off-by: Nicolas Bouchinet --- drivers/tty/tty_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 407b0d87b7c10..f211154367420 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3631,7 +3631,7 @@ static struct ctl_table tty_table[] = { .data = &tty_ldisc_autoload, .maxlen = sizeof(tty_ldisc_autoload), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, },