Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1788983lqm; Fri, 3 May 2024 06:44:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUlh5o/uYGDDyz9+P27lto6Otf6LVFL+Rhf0rUEj2Ykm4xyZCTsTG6rCnfti5IE2CYgkZsFT+S6NSsu39EDMvpVM5Cc0H/VoqAtx1k4Bg== X-Google-Smtp-Source: AGHT+IGDZoPPztVND3fPs8yExr5Q4cUM/0ekwWuuR+BOVeAFX7noheoyzIdRprW+hRZ0S8fy6sDb X-Received: by 2002:a05:620a:bd6:b0:790:eed5:53f with SMTP id s22-20020a05620a0bd600b00790eed5053fmr10294707qki.1.1714743884932; Fri, 03 May 2024 06:44:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714743884; cv=pass; d=google.com; s=arc-20160816; b=E8PxNIUXYVjFqgTvogzYJv/6lUeHPo7QQVPNZ9B0Txiez2pAkuu3RrPCvBirJOL1qS ga9H+iaftXC6FDJ151pWA3IE9TOnoc5yuYZPEpLNMq+YZZyB99GIvZKS9B+M9psyUDs5 rWarF+4ZcE00bBMTrbWHGo6wUu5x0Z95m5QbW/I7tKCdl9p1sztjP75oldh/Bn9wCMkb wyIdDjHfCv016QYh2heCNtXEQJHiKFfUqe8zhRxnXmKiG2HMyDYTExLYwfbV6SjIW8af C4Fo+amjktLIQdx92xBzXZP8XoI3enUgyyYAlyDgItnr8WWYwbOvUVV3m38mucM3wyr0 NIMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=aAEPjTHkY68KhTzM83PdfHcfTCA5cMbJGy3m5Y+dR/A=; fh=emQ4WF0/Njgs3HzdsYYp6PxnFGam3Bk81Doj2fx5ggo=; b=RteCyOCMdD/1FGm0kjwphb8kEq9IQQL/M4Ie+Co3v9TkaoxxVKw5gDYSXAFTjLY1sI XAjYOYd4eBfVV3Yl3cKOfIfbYJKEMcDSWrwgkgXp7oRnnDYOUT1eH3mVpLvCDC57b5dz Ee8K+sB+Uphkpgx2r369wglmQ9VrgUzMQOAzSSoQD9FcOcnmLNV2BknxPs3Kl2XVrnzB FnUF/Jqq15vJ57f+l7JvOlfsdMBEDYSH7lcmXP0ZvGXrLmO/4wF3zMOFTuSxcBFd4gkj vdTfcnpkreAiOEMdb+HX0ctjTjol1aWwdcFrxhoFjtaDgpIKoErL5MO8z3lPAJ9LE47N S8Qw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=cvx0cKi+; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-167718-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167718-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g13-20020a05620a108d00b00790f9054e70si3089196qkk.522.2024.05.03.06.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 06:44:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167718-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=cvx0cKi+; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-167718-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167718-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A074A1C213BE for ; Fri, 3 May 2024 13:44:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1506E153BE6; Fri, 3 May 2024 13:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="cvx0cKi+" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 8B8B5153BC9; Fri, 3 May 2024 13:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714743876; cv=none; b=WYPKFgGOOZnPqd1GT9m8T8GsjoOUCYo+bSEdiAL3fCF8V+AED9dGUcY+7DcHspP/ZCZMXweBH2AWimD7rUA2MZJbRFgmT3KQ9y25Itps0Z7KL3bMRGq+XWEJWKnaH3/QSyO9pllPfnrT1+aQIiKRmDBitfI8p2Oj/QF8GV7mkSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714743876; c=relaxed/simple; bh=5+w0EO0csO5S2boUJzwf6vkebCqsTwn1sGI9xWIoSyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=YApFiZ8nqcbvrXmt6US9dx/NUh8FQrE56uZRPc0t3ZgJWbt/THe/dFrj9h0dlWo7idzLv0kGTI/IHio9Ry395O4ucyNZVZyZDxIIogL11FlDwY/Bqb9UsqzWxMM1xVc4jno2Qv4o+jqhn+pvaxhTmoXB73eFElRgiKqXIFUaxbM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=cvx0cKi+; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1714743868; bh=5+w0EO0csO5S2boUJzwf6vkebCqsTwn1sGI9xWIoSyU=; h=From:Date:Subject:To:Cc:From; b=cvx0cKi+VKcX0P2kD76tfscHjmwGbHpA4KQCUWGGS7kexQOinNr+6YxZaF69PgIxS +SKjMSczqersGVWZbhPVPlyRkEjADqD3qv2RFtKL9z/9x+oyiLA+/MJ0XvLUe3hiUP GlovuEA0OKfel9xvFOvBPlQnp9Bt00azA7VEDUWM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 03 May 2024 15:44:09 +0200 Subject: [PATCH] stackleak: don't modify ctl_table argument Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240503-sysctl-const-stackleak-v1-1-603fecb19170@weissschuh.net> X-B4-Tracking: v=1; b=H4sIACjqNGYC/x3MSwqAMAwA0atI1gbqH7yKuKgxalCqNEUU8e4Wl 28x84CyF1Zokwc8n6Kyu4gsTYAW62ZGGaMhN3lpKlOg3kphQ9qdBtRgad3YrmingutmoLoaDMT 48DzJ9Y+7/n0/87RKS2gAAAA= To: Kees Cook , Alexander Popov Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Luis Chamberlain , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Joel Granados X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714743866; l=2040; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=5+w0EO0csO5S2boUJzwf6vkebCqsTwn1sGI9xWIoSyU=; b=fBMwaLymZDWl5ESfaeFhtKSN21HcxU3lGdUMe7amXumuUxJ8R3pU98RUVKAHdADhkqwTzqqOE 6Q4w5KGOAnzAMGUTgSYojEJjABmbZbji4viqFCO8IPS7Tc5/H9auPlR X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Sysctl handlers are not supposed to modify the ctl_table passed to them. Adapt the logic to work with a temporary variable, similar to how it is done in other parts of the kernel. This is also a prerequisite to enforce the immutability of the argument through the callbacks prototy. Fixes: 964c9dff0091 ("stackleak: Allow runtime disabling of kernel stack erasing") Cc: stable@vger.kernel.org Acked-by: Kees Cook Reviewed-by: Luis Chamberlain Signed-off-by: Thomas Weißschuh --- This was split out of my sysctl-const-handler series [0]. As that series will take some more time, submit the patch on its own, as it is a generic bugfix that is valuable on its own. And I can get it out of my books. Changelog in contrast to the patch in the series: * Reword commit message to remove strong relation to the constification * Cc stable [0] https://lore.kernel.org/lkml/20240423-sysctl-const-handler-v3-0-e0beccb836e2@weissschuh.net/ Cc: Joel Granados --- kernel/stackleak.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/stackleak.c b/kernel/stackleak.c index 34c9d81eea94..b292e5ca0b7d 100644 --- a/kernel/stackleak.c +++ b/kernel/stackleak.c @@ -27,10 +27,11 @@ static int stack_erasing_sysctl(struct ctl_table *table, int write, int ret = 0; int state = !static_branch_unlikely(&stack_erasing_bypass); int prev_state = state; + struct ctl_table tmp = *table; - table->data = &state; - table->maxlen = sizeof(int); - ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); + tmp.data = &state; + tmp.maxlen = sizeof(int); + ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); state = !!state; if (ret || !write || state == prev_state) return ret; --- base-commit: f03359bca01bf4372cf2c118cd9a987a5951b1c8 change-id: 20240503-sysctl-const-stackleak-af3e67bc65b0 Best regards, -- Thomas Weißschuh