Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1164766ybf; Thu, 27 Feb 2020 06:11:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwz7n4Sc5/BOa9tpmD16RoRnYfrDg6jVOBoIzkFWE3ADthxSTPagQc2dE9JGYHu7oIuIOlV X-Received: by 2002:a9d:74c4:: with SMTP id a4mr3525657otl.119.1582812691232; Thu, 27 Feb 2020 06:11:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812691; cv=none; d=google.com; s=arc-20160816; b=hZipyXV9pKaOByPC9XK3maKHvC1IuoJALjx7UMXe7hRsh3uTQv+Q9Hbw51TzM3tOz0 WC9cpzgdkYvXd/ZVauYN23+Id4x+ZwXb7YeqSKM4WO45VOCa5T1vBm2K3y1qT+3fXe79 Ent/VKY3dLzfEp2iQAZMz+Ow1Oo3qm+v+MXNZHbN9i3jlFAO0VDbln1ReU93gT5b5gCa UUnMXDYrWxPm8SXpMGxNOhCIQSx1x0H3sCxDxW+6fmxq6YoGHBK77HQbFTuoJAdwYxEq s90mQrtyPzApqKAjjnyExjRvQH7mp5jHG8q/kBFJb10JncY5KjPkdBQ/It2/yCZ4cbXQ FDWw== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B4BT8DYPTy0/93do+/8bv9QuD+GaBEH+o8rXUjq/ICY=; b=GQ9wm4Y7nIP4e8qUjAoPYu+EniVjGQQGqxDlUrjV4YtXIZxVak4N8GiezKp5U17d9W N/TL7zHveP9Ab2MjinSVoypsqSyYkKVv5Y7dX9La+q5iecBpQwei5kh41OSLbcUY4EYD 8XEm29y54RmLPe5MsC6tEDjtL27ImNJSPwcEIfDs7Y/sTPk9BZI9NM40vbwB6aYqGd9K JPIchxUs5jfauU6fNaS0PlCsWQCPtZ/icNvlVXWNmJEGcgZoREs3B+LRb96QpsSi7w4V I0onpcrvWCyVfdmI30QePyBVvRHqtpZplIz+PQA4aycHGIwJpTQz015KUcmMJbQ7IHJN weEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="AjAiW/Pd"; 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 i6si1903026otj.24.2020.02.27.06.11.14; Thu, 27 Feb 2020 06:11:31 -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; dkim=pass header.i=@kernel.org header.s=default header.b="AjAiW/Pd"; 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 S2388241AbgB0OJx (ORCPT + 99 others); Thu, 27 Feb 2020 09:09:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:47810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733262AbgB0OJs (ORCPT ); Thu, 27 Feb 2020 09:09:48 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 876C120801; Thu, 27 Feb 2020 14:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812588; bh=8dJc3VjqGnWWFG3e8ysCnj4VZcKV3ZJX84/9oq8ZYP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AjAiW/PduskoKG/aLvKEthuUq/oF5Sp8nQ8Zav5gY4mS0gAeM1Hu5sJmqFA/ZgGpx Tm9gLoVTkSoKmBJBS5ugJRRP2Dob+z010eR7geATHQsYKhoKFez1epVUm75SDMUqSt tjcbpiU8fzr+4uJHe39rZxsI3VMh5IyfC3HPwJMc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suren Baghdasaryan , "Peter Zijlstra (Intel)" , Ingo Molnar , Johannes Weiner Subject: [PATCH 5.4 076/135] sched/psi: Fix OOB write when writing 0 bytes to PSI files Date: Thu, 27 Feb 2020 14:36:56 +0100 Message-Id: <20200227132240.815487769@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suren Baghdasaryan commit 6fcca0fa48118e6d63733eb4644c6cd880c15b8f upstream. 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 Signed-off-by: Greg Kroah-Hartman --- kernel/sched/psi.c | 3 +++ 1 file changed, 3 insertions(+) --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1199,6 +1199,9 @@ static ssize_t psi_write(struct file *fi 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;