Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp5144019pjo; Tue, 11 Feb 2020 04:50:03 -0800 (PST) X-Google-Smtp-Source: APXvYqy4vjUnIsqjGbce5gYs4mZNlERu3ybPLWiOz4U2FmTbbdhQot3sUMtKKB+v1X0NZsy9u71u X-Received: by 2002:a05:6808:3ba:: with SMTP id n26mr2810806oie.62.1581425403603; Tue, 11 Feb 2020 04:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581425403; cv=none; d=google.com; s=arc-20160816; b=ML1w/0qgGhiIYFKRqebOnDq3ZMO5Cf8Hp1PqL9SP5tn103W00x2RkP2VSSnFsNjtLx 6vkwdKp5jNxnOdOoBi/dDtCW7f6Fes5MKmLJeWVa7yPqTcj6D/ZoML5kkOXAN9gms9Uf rOVE99+c+XPiy8dHGI8bPYKGqU9K/+fuSSChB46kd9abQYesebbOqi1YGFE1/2DaLS2N uJbHR2abYYP/2f758nO1cVA18/NvXt2h2Qki/nw+GjszD2v/ZLqufO3j6seLI/91wePe IsSriCpwUppceCKUo29299KW0bte3YyF1G9KzU1i/IjR64BLGkr8etnvSw8PB9ZsaPBz Xlow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=oG/d8CBUBuWj7t2B4SSzB26IhtLiyWrPQaG6HbkWj3Q=; b=z5a4VmCnrj7ZmyOb/TXBwQD/5QzFUrCrvYEPndg/12BCtDqSMN9xUW9yAsIJ4/iMSm KZio8GEqRP3tC07tDdf85+PMU03j30zI8PYoN27xr4/+2AIu4vNokUkR0RPcsezamF4D NsEsgsMX4tPuhoUsLlYsnaYgCw20tzAY05jDlaNv7crpK0iGgkCkEbrFPh9+SP3s9Kit ulk3VGFVC0bDwBZYhEX3rentECKq9dFM8/XA6cczqpJhgl+V/BJVgvz3xi0T2SF/cxgz Z8ge5Gp2I7mzclpszga4/oiN6+089JbdWrcSKFEKHOgPMtHLA984OCNqNCneR1cV6ASi j3Dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si1621149oic.18.2020.02.11.04.49.52; Tue, 11 Feb 2020 04:50:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728664AbgBKMr7 (ORCPT + 99 others); Tue, 11 Feb 2020 07:47:59 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:46029 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728636AbgBKMr6 (ORCPT ); Tue, 11 Feb 2020 07:47:58 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j1UxF-0007bT-Jl; Tue, 11 Feb 2020 13:47:53 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 2F2D91C2018; Tue, 11 Feb 2020 13:47:48 +0100 (CET) Date: Tue, 11 Feb 2020 12:47:47 -0000 From: "tip-bot2 for Suren Baghdasaryan" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] sched/psi: Fix OOB write when writing 0 bytes to PSI files Cc: Suren Baghdasaryan , "Peter Zijlstra (Intel)" , Ingo Molnar , Johannes Weiner , x86 , LKML In-Reply-To: <20200203212216.7076-1-surenb@google.com> References: <20200203212216.7076-1-surenb@google.com> MIME-Version: 1.0 Message-ID: <158142526792.411.11655053168783625036.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/urgent branch of tip: Commit-ID: 6fcca0fa48118e6d63733eb4644c6cd880c15b8f Gitweb: https://git.kernel.org/tip/6fcca0fa48118e6d63733eb4644c6cd880c15b8f Author: Suren Baghdasaryan AuthorDate: Mon, 03 Feb 2020 13:22:16 -08:00 Committer: Ingo Molnar CommitterDate: Tue, 11 Feb 2020 13:00:02 +01:00 sched/psi: Fix OOB write when writing 0 bytes to PSI files Issuing write() with count parameter set to 0 on any file under /proc/pressure/ will cause an OOB write because of the access to buf[buf_size-1] when NUL-termination is performed. Fix this by checking for buf_size to be non-zero. Signed-off-by: Suren Baghdasaryan Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Acked-by: Johannes Weiner Link: https://lkml.kernel.org/r/20200203212216.7076-1-surenb@google.com --- kernel/sched/psi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index db7b50b..38ccd49 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1199,6 +1199,9 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf, if (static_branch_likely(&psi_disabled)) return -EOPNOTSUPP; + if (!nbytes) + return -EINVAL; + buf_size = min(nbytes, sizeof(buf)); if (copy_from_user(buf, user_buf, buf_size)) return -EFAULT;