From patchwork Wed Jul 20 04:20:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 9238843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD72D602F0 for ; Wed, 20 Jul 2016 04:23:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4CFA20587 for ; Wed, 20 Jul 2016 04:23:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C995E2756B; Wed, 20 Jul 2016 04:23:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56A9F20587 for ; Wed, 20 Jul 2016 04:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753172AbcGTEXK (ORCPT ); Wed, 20 Jul 2016 00:23:10 -0400 Received: from alt32.smtp-out.videotron.ca ([24.53.0.21]:39017 "EHLO alt32.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751420AbcGTEUt (ORCPT ); Wed, 20 Jul 2016 00:20:49 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id Pj02bQmeAYOXTPj03bCFYz; Wed, 20 Jul 2016 00:20:47 -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 E3CF72DA05AD; Wed, 20 Jul 2016 00:20: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 v3 03/12] binfmt_flat: prevent kernel dammage from corrupted executable headers Date: Wed, 20 Jul 2016 00:20:15 -0400 Message-Id: <1468988424-32671-4-git-send-email-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468988424-32671-1-git-send-email-nicolas.pitre@linaro.org> References: <1468988424-32671-1-git-send-email-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfH9ElPo5OrLPB8HxDaIxqdepYExVvpgkJoI+4NwD+etNVsRB9ypjBBKJrlHM77fdXjEruHPLlMnNbkM4a5251wOqe1npEeRMnsRdGwF4biQKznwyAL4S sa8duejb4bKlOgWNCpE3C3b+QwxnJIucUEBKfh5wvB05/o57epanmjgLwbW5yekKag9bbsUaEUtGIXnzE1l9M9UOLxleP4FTc9fiNMJQBFxPtW4HzxJQfHc6 9hlJ4YuLiHTXj3DACHG7vbDhdxfOnwSrRby/giufhW7fRQStI0JxkCm60pRsvJy3BtWL/f8ej0Jy4b4L3j6xMA== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nicolas Pitre --- fs/binfmt_flat.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 36f5bb6b2c..9c76d9a222 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -470,6 +470,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 */