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: 11052355 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 B164E6C5 for ; Mon, 22 Jul 2019 13:21:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FA8227FC0 for ; Mon, 22 Jul 2019 13:21:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 928482837E; Mon, 22 Jul 2019 13:21:17 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 2BF9427FC0 for ; Mon, 22 Jul 2019 13:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725989AbfGVNVQ (ORCPT ); Mon, 22 Jul 2019 09:21:16 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40129 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbfGVNVQ (ORCPT ); Mon, 22 Jul 2019 09:21:16 -0400 Received: by mail-wr1-f68.google.com with SMTP id r1so39395274wrl.7 for ; Mon, 22 Jul 2019 06:21:15 -0700 (PDT) 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=AalcruJ6WfWetIF8Sp6xgw7gckIAwOsWZFyZvIPGWpOuOUfUVmrEfH5lOvpnRzHYiA ubWtPZrbOtTkKD2OWrwgqk08NAp7yF4eyletnY5li0wZB+Z1EYMj9DmnNIBgDWJfiLc6 IDXo8epVCZwfuGEWWMR8s/VQ+6L/kWkLNFYwJ+mziT6161m89U5qtAG7rs/tmV7eIlq3 BAbGlFdz93QkgSYWmCqZsc89A8YdV34yUzWe0iN8rpW4VDMV9D2oG+tHv6s5oi4ad0C9 UDoRDDfi9YeCH2u+7/EdzaDNmWzeemwO6olixfAgYKsAT/s7aaBIo9D1DZyorPVPtiEe 4h7Q== X-Gm-Message-State: APjAAAV8J2ZSrkY4C3VWT9XF26BGDzmXmpcyLTs0VuPewV18vpDmsPrf vYPdkAen8II2WXgG7hTeR82HTGyFm2A= 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) Received: from localhost.localdomain.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id f70sm46021087wme.22.2019.07.22.06.21.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 22 Jul 2019 06:21:13 -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 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org 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);