From patchwork Wed Jul 20 19:22:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 72473 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp43939qga; Wed, 20 Jul 2016 12:23:55 -0700 (PDT) X-Received: by 10.98.216.199 with SMTP id e190mr67499903pfg.123.1469042630214; Wed, 20 Jul 2016 12:23:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si4858995pag.285.2016.07.20.12.23.49; Wed, 20 Jul 2016 12:23:50 -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 S1755246AbcGTTXl (ORCPT + 29 others); Wed, 20 Jul 2016 15:23:41 -0400 Received: from alt13.smtp-out.videotron.ca ([135.19.0.26]:10065 "EHLO alt12.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754697AbcGTTWt (ORCPT ); Wed, 20 Jul 2016 15:22:49 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id Px4vbh5ICq3HFPx4wb4WQ6; Wed, 20 Jul 2016 15:22:47 -0400 X-Authority-Analysis: v=2.1 cv=Q9lym9Ca 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 61DE52DA05AD; Wed, 20 Jul 2016 15:22:45 -0400 (EDT) From: Nicolas Pitre To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexander Viro , David Howells , Greg Ungerer Subject: [PATCH v4 03/12] binfmt_flat: prevent kernel dammage from corrupted executable headers Date: Wed, 20 Jul 2016 15:22:32 -0400 Message-Id: <1469042561-7360-4-git-send-email-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469042561-7360-1-git-send-email-nicolas.pitre@linaro.org> References: <1469042561-7360-1-git-send-email-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfA/Ac7cLKHRS/Bi+YUhAstEAy/WkWpFTa8D5fpEcPVppWjDHipZTvr5V5w+lMpMK3woWPkPvICdvPRpjOuFVxlO7IlNBNPIGdqBkgOEFA4Hl1hdK/yx6 QJ5uxIYo9x53/1L7cWJzHXhWDBgFNoUYacZjxeZ7UAG09y/lL95cQEhgNSxtK3mnOhDKcmcL+UsNqnAMPpc0JaHlbZSLPmQeajvcgPON2dGOif4D9Cbl+K3W 6vhEbKMSuuZOkES64v38He04P0u2bdOeXGpraX/uKsaChQOi8aJgc5WrVIy2Cx85T0YSRBbWHULUC5DusYtYEw== 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 */