From patchwork Thu Jan 2 22:07:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234776 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F9CAC3276C for ; Thu, 2 Jan 2020 22:17:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9D312464B for ; Thu, 2 Jan 2020 22:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003466; bh=cDGxvQ6VaN64SpWCnKdSQZiZKTB9gPZsUPK1SbMRtkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j26gqhz7QjXqdy44qUanH/5+NiOrwI19utNXPyTnh/jjrW2NrcGHbelNnPduAj1W/ 2zkUk2vHImT8tZJ9kvHPGHw1bf+oJCx2GIlLTqyI7P1UnJtVHHZNt/V75iZh8qR13Y 24OOdPfKMh7WO2gSJyvnzG2QfrZq2KwK0Z6vD6P8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727443AbgABWRo (ORCPT ); Thu, 2 Jan 2020 17:17:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:60404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728112AbgABWRm (ORCPT ); Thu, 2 Jan 2020 17:17:42 -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 4B22B21582; Thu, 2 Jan 2020 22:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003461; bh=cDGxvQ6VaN64SpWCnKdSQZiZKTB9gPZsUPK1SbMRtkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTpqaWOJ8DgZv5dypiPatNiT5Ae+fx0Dn+wikmJdgEAz6m/FTyCoxnEPI1jObwl5Y KEkh8Xds2tdajJlEQOdx9htnaqPzWSYb6Rzn0qwCsifLqo+mBUIbsz9llBUIYkc6oA 70+AC8/45q60riHyBi39k3VRmUhHqQJgEE2bncds= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Dan Carpenter , Alexander Viro , Andrew Morton , Linus Torvalds Subject: [PATCH 5.4 144/191] uaccess: disallow > INT_MAX copy sizes Date: Thu, 2 Jan 2020 23:07:06 +0100 Message-Id: <20200102215844.953035794@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Kees Cook commit 6d13de1489b6bf539695f96d945de3860e6d5e17 upstream. As we've done with VFS, string operations, etc, reject usercopy sizes larger than INT_MAX, which would be nice to have for catching bugs related to size calculation overflows[1]. This adds 10 bytes to x86_64 defconfig text and 1980 bytes to the data section: text data bss dec hex filename 19691167 5134320 1646664 26472151 193eed7 vmlinux.before 19691177 5136300 1646664 26474141 193f69d vmlinux.after [1] https://marc.info/?l=linux-s390&m=156631939010493&w=2 Link: http://lkml.kernel.org/r/201908251612.F9902D7A@keescook Signed-off-by: Kees Cook Suggested-by: Dan Carpenter Cc: Alexander Viro Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/thread_info.h | 2 ++ 1 file changed, 2 insertions(+) --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -147,6 +147,8 @@ check_copy_size(const void *addr, size_t __bad_copy_to(); return false; } + if (WARN_ON_ONCE(bytes > INT_MAX)) + return false; check_object_size(addr, bytes, is_source); return true; }