From patchwork Mon Jul 22 13:21:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Mosnacek X-Patchwork-Id: 11052431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAA8D746 for ; Mon, 22 Jul 2019 13:45:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCABD20501 for ; Mon, 22 Jul 2019 13:45:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0745282EC; Mon, 22 Jul 2019 13:45:53 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id DEC0828450 for ; Mon, 22 Jul 2019 13:45:52 +0000 (UTC) Received: (qmail 9305 invoked by uid 550); 22 Jul 2019 13:45:51 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 24098 invoked from network); 22 Jul 2019 13:21:25 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6xdFD26pzy0BMDeFjS2w4OeuE3vbxUzI4nJ0HnGm5ug=; b=lt86FTgM1hUDMPbTxRnLkrNFRySeOIjfVJo9b9roiAtYlW6EKf/V67JpR9ffJB6uJe pp3K/xj0EGaX8qRbo7gP4Vy+PdijnM5w+Lem/5U9J6lJd3P3vhOAcpFWUeAdpyU06bP5 evP0uOAJPKWE4xy2IglYtpRVI8iqhFbl2dica27wXDl1wvnmK5ZufGUplGq+TLslp6So Ccz1L0fSMV7VMFfjssuoe0l4h2HeL+5T7o5X46oRKHv54lwC3yqM68y1Vi6nHjzO8/pO f3SWWEaH+SCL/26Sqh0KBgZHM+c5v71hLJodfnsl7O+sTSOxFPlbzGKx7C+V9kY2EVxD 0U9w== X-Gm-Message-State: APjAAAV3FpsMaB4jQNu3Z0dmq0/16fNl+j/Umjx4YCQ8YKNVmNBSWvWe FohUe6NOukRuRxuFgYXtu3U49A== X-Google-Smtp-Source: APXvYqwMNDPSQy9ey7HxRTb4UR6sXwjdyOcJy6lL3Od55VZGCNZO1lT9/D6hKg/gJFNitDWBaLbjEw== X-Received: by 2002:adf:e843:: with SMTP id d3mr26317115wrn.249.1563801674266; Mon, 22 Jul 2019 06:21:14 -0700 (PDT) From: Ondrej Mosnacek To: selinux@vger.kernel.org, Paul Moore Cc: NitinGote , kernel-hardening@lists.openwall.com, Kees Cook Subject: [PATCH] selinux: check sidtab limit before adding a new entry Date: Mon, 22 Jul 2019 15:21:11 +0200 Message-Id: <20190722132111.25743-1-omosnace@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP We need to error out when trying to add an entry above SIDTAB_MAX in sidtab_reverse_lookup() to avoid overflow on the odd chance that this happens. Fixes: ee1a84fdfeed ("selinux: overhaul sidtab to fix bug and improve performance") Signed-off-by: Ondrej Mosnacek --- security/selinux/ss/sidtab.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/security/selinux/ss/sidtab.c b/security/selinux/ss/sidtab.c index e63a90ff2728..54c1ba1e79ab 100644 --- a/security/selinux/ss/sidtab.c +++ b/security/selinux/ss/sidtab.c @@ -286,6 +286,11 @@ static int sidtab_reverse_lookup(struct sidtab *s, struct context *context, ++count; } + /* bail out if we already reached max entries */ + rc = -ENOMEM; + if (count == SIDTAB_MAX) + goto out_unlock; + /* insert context into new entry */ rc = -ENOMEM; dst = sidtab_do_lookup(s, count, 1);