From patchwork Sun Jul 24 15:30:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 72666 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp743600qga; Sun, 24 Jul 2016 08:31:01 -0700 (PDT) X-Received: by 10.98.16.193 with SMTP id 62mr22567750pfq.132.1469374261679; Sun, 24 Jul 2016 08:31:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oo4si28484556pac.59.2016.07.24.08.31.01; Sun, 24 Jul 2016 08:31:01 -0700 (PDT) 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752170AbcGXPam (ORCPT + 29 others); Sun, 24 Jul 2016 11:30:42 -0400 Received: from alt32.smtp-out.videotron.ca ([24.53.0.21]:54525 "EHLO alt32.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751598AbcGXPai (ORCPT ); Sun, 24 Jul 2016 11:30:38 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id RLMRbeEZ5YOXTRLMSbJ3GY; Sun, 24 Jul 2016 11:30:37 -0400 X-Authority-Analysis: v=2.1 cv=Gfm35VjL c=1 sm=1 tr=0 a=keA3yYpnlypCNW5BNWqu+w==:117 a=keA3yYpnlypCNW5BNWqu+w==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=cAmyUtKerLwA:10 a=KKAkSRfTAAAA:8 a=TjqNXoBTBnqrC5BxUBMA:9 a=cvBusfyB2V15izCimMoJ:22 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id 6AAA52DA0661; Sun, 24 Jul 2016 11:30:35 -0400 (EDT) From: Nicolas Pitre To: Greg Ungerer , linux-fsdevel@vger.kernel.org Cc: Alan Cox , Alexander Viro , David Howells , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 03/15] binfmt_flat: prevent kernel dammage from corrupted executable headers Date: Sun, 24 Jul 2016 11:30:17 -0400 Message-Id: <1469374229-21585-4-git-send-email-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469374229-21585-1-git-send-email-nicolas.pitre@linaro.org> References: <1469374229-21585-1-git-send-email-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfOjXYC9AqIWKaklKds8Kl7D08T1vkESO3m+8Tk+Agfv3TnmycP3ZmCSuBJEJCedz9qkU4RAjUMav+oPnmXl7fR/k7QDs2i/l80VLPRZ/nO6j0a2rRqKp bka1NDsEgw+KavkQBf5Z3t15lVbARngbBXDKM2sQ12W7u3hymu4pKVYa4p448NL5+wj3p/5xr4sv4fS5MEAMG6wdmQxmTtTVDZkydh+nMG+8R4GZNUY6o4FA dvibcadrA3i1fN62073OtzX23fwH8DGI3qzYmNZnMs7VBwhi7q3coLT+b3dO5lUo0wd/OQNYKcauVpemMISbPkRrzOG1XN19RjSriL6lFtEpKWOy6TQPEydi htpT1jWi0ZTLfiK8nqhwOQUaQ9kNqbhsYsGgP9Ar41JMhDohxOlBT4UFVkt2PpQ7W2qMnzgMnpoCACYt5rVmluQWJneW2APNFDYuScLuFgfZmk5NYDU= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Nicolas Pitre --- fs/binfmt_flat.c | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.7.4 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index c3ccdefdea..03301bad1f 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -466,6 +466,17 @@ static int load_flat_file(struct linux_binprm *bprm, } /* + * Make sure the header params are sane. + * 28 bits (256 MB) is way more than reasonable in this case. + * If some top bits are set we have probable binary corruption. + */ + if ((text_len | data_len | bss_len | stack_len | full_data) >> 28) { + pr_err("bad header\n"); + ret = -ENOEXEC; + goto err; + } + + /* * fix up the flags for the older format, there were all kinds * of endian hacks, this only works for the simple cases */