From patchwork Fri Mar 24 17:51:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9643489 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 C3F4D60328 for ; Fri, 24 Mar 2017 17:51:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9B651FF87 for ; Fri, 24 Mar 2017 17:51:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE89C267EC; Fri, 24 Mar 2017 17:51:51 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A55A1FF87 for ; Fri, 24 Mar 2017 17:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=DNWwNxu4CE3N0MEJzmDbR9x6MmAgqTfmqJHt68Tzzug=; b=p9+T/N629pP3Iq vVi0gYm+oce+pSr/voilowyTCKLxVXqy/IXePdTyduRSK6oU35fJHZnbcZJwPoUottjrvBVyk9Vgs /TKZY4tZY6bg1Weo/IUHqMamVCrghpO9bLOxojEbP9uSXXlPrPFPpLhGdDpXUxRhbXSeMclxbMkqs XwolrtvxvhYCZbrt0mjPvcsy0FaNUBpdrvT5ZGOE16f14hMC72zXx33O19TlxD20I1gTd9nQ/k+E+ A+c1/kwAyeFrsThXppXoJ+RYMYcKOTMmtthAwBEk3RaNkh/7CEPU1P1dLIOejM/cDeypw2LDJF+As sE3sSv1rb9fwNQrpVkFg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1crTNP-0007kX-0u; Fri, 24 Mar 2017 17:51:51 +0000 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1crTNM-0007fE-9E for linux-arm-kernel@lists.infradead.org; Fri, 24 Mar 2017 17:51:49 +0000 Received: by mail-pg0-x22a.google.com with SMTP id 21so4522293pgg.1 for ; Fri, 24 Mar 2017 10:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=0kwpzUN0uw2S3DLIas6vPLCpBrs58fWYscoNrcXwjeE=; b=ZlWz3tx4Nj2UptqAB/9vQfrN2Y9Tpr1FYNUtVKZQ8N7jZF1nlTQWsfoxgww6Jj1+Xp e7MN1a7+FUcHkXms93ibRqHVCCGHqN3T7/jQ/+LxOu/9ClVC/QBPTSNMUFUYLIFgmOx6 jcPD9yqYigKbRA5MZWL5gnX/oGNc60LYd+gg8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=0kwpzUN0uw2S3DLIas6vPLCpBrs58fWYscoNrcXwjeE=; b=L8/039t5LV7f3itypuPgaJXA1I+PDqqPKCHKYZIVm0qcZuPhvvEma0RvRJ55QxMP5s 1QxmgWAP2LsaXkSmcptIqX7GdX7exIVbQH56UxxrifvDZesruplub9YSpzRIhY73HbmV vnwlU5zkuM9tCtBqC1DkZ1DCxn//egI3ZhNKTG7uZbV4P9Lyv9RKYJAhbbUxgWEThcR+ dsHOZQZPg2yKduWcP0KJ9hsGnW8ny+mC3htVVipwZsE6tIkjLZIjJFIPPJDfYbEJfEUw I/HiK44th4M6lyxot/Zpe4anFKzIHKNb5cTbYE4HnBWxcGmqPLnq6wPCWy6WpzTETxOw 08yg== X-Gm-Message-State: AFeK/H2XwnHLEBpu/fZkqERXOk7J/jf2rpmVNcBjfEDEcdYErj/RDw5yAe+2fm0+Q/hmdKJq X-Received: by 10.99.102.134 with SMTP id a128mr10293363pgc.215.1490377887452; Fri, 24 Mar 2017 10:51:27 -0700 (PDT) Received: from www.outflux.net ([2002:ada4:7085:0:fcc0:da09:7cea:a56d]) by smtp.gmail.com with ESMTPSA id c75sm5948171pga.22.2017.03.24.10.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Mar 2017 10:51:26 -0700 (PDT) Date: Fri, 24 Mar 2017 10:51:25 -0700 From: Kees Cook To: Thomas Garnier Subject: [PATCH v2] lkdtm: add bad USER_DS test Message-ID: <20170324175125.GA108985@beast> MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170324_105148_358694_472CDCF5 X-CRM114-Status: GOOD ( 14.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-s390@vger.kernel.org" , "kernel-hardening@lists.openwall.com" , "x86@kernel.org" , Heiko Carstens , LKML , Christian Borntraeger , "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This adds CORRUPT_USER_DS to check that the get_fs() test on syscall return (via __VERIFY_PRE_USERMODE_STATE) still sees USER_DS. Since trying to deal with values other than USER_DS and KERNEL_DS across all architectures in a safe way is not sensible, this sets KERNEL_DS, but since that could be extremely dangerous if the protection is not present, it also raises SIGKILL for current, so that no matter what, the process will die. A successful test will be visible with a BUG(), like all the other LKDTM tests. Signed-off-by: Kees Cook --- drivers/misc/lkdtm.h | 1 + drivers/misc/lkdtm_bugs.c | 11 +++++++++++ drivers/misc/lkdtm_core.c | 1 + 3 files changed, 13 insertions(+) diff --git a/drivers/misc/lkdtm.h b/drivers/misc/lkdtm.h index 67d27be60405..3b4976396ec4 100644 --- a/drivers/misc/lkdtm.h +++ b/drivers/misc/lkdtm.h @@ -27,6 +27,7 @@ void lkdtm_REFCOUNT_ZERO_SUB(void); void lkdtm_REFCOUNT_ZERO_ADD(void); void lkdtm_CORRUPT_LIST_ADD(void); void lkdtm_CORRUPT_LIST_DEL(void); +void lkdtm_CORRUPT_USER_DS(void); /* lkdtm_heap.c */ void lkdtm_OVERWRITE_ALLOCATION(void); diff --git a/drivers/misc/lkdtm_bugs.c b/drivers/misc/lkdtm_bugs.c index e3f4cd8876b5..ed4f4c56c796 100644 --- a/drivers/misc/lkdtm_bugs.c +++ b/drivers/misc/lkdtm_bugs.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include struct lkdtm_list { struct list_head node; @@ -279,3 +281,12 @@ void lkdtm_CORRUPT_LIST_DEL(void) else pr_err("list_del() corruption not detected!\n"); } + +void lkdtm_CORRUPT_USER_DS(void) +{ + pr_info("setting bad task size limit\n"); + set_fs(KERNEL_DS); + + /* Make sure we do not keep running with a KERNEL_DS! */ + force_sig(SIGKILL, current); +} diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c index b9a4cd4a9b68..42d2b8e31e6b 100644 --- a/drivers/misc/lkdtm_core.c +++ b/drivers/misc/lkdtm_core.c @@ -199,6 +199,7 @@ struct crashtype crashtypes[] = { CRASHTYPE(OVERFLOW), CRASHTYPE(CORRUPT_LIST_ADD), CRASHTYPE(CORRUPT_LIST_DEL), + CRASHTYPE(CORRUPT_USER_DS), CRASHTYPE(CORRUPT_STACK), CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE), CRASHTYPE(OVERWRITE_ALLOCATION),