Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3804647ybi; Mon, 29 Jul 2019 12:59:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXNHvLtxFtp9iP6csJUwVI69O6K9irNymfEZGMX1/10qSFwDwGTKVD8Z5Jfl8beQI+D33R X-Received: by 2002:a17:902:9a06:: with SMTP id v6mr108766686plp.71.1564430346340; Mon, 29 Jul 2019 12:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430346; cv=none; d=google.com; s=arc-20160816; b=ZCt3o6IougtmRlHQd/tqBBtQDB7Tm0qeUOaeF7/U3W4LfqLUvBkGJNZUC0IX5HEK7V 35Lixw6WUQlPm6MT697lcflE+4BE8PpG0Mm0pit/aUmwZTnp3sazXczUQjjJXXo9oky2 v/UhnAhDNY38teFUR3h+pmhQQzEE6JJJvo5uhMwjB3QDlm3ONk12nb8U50eeAbiAGEzU cn9qUhhlEFlynHa9HfLfrKzxDnVJUvHngp1nBySx1326mjR1k3qen2wcUc/W0hJ2r8lp VO8SGK7T1PxmtX8Yd/HClsKde9f6RXDGsDaS3NFkG1OY7PyPH/QRrQ6R2j8X/PavSrK3 ALVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HeeeFEKnGKJ2xjPg2/jNLJot14m/+XQr2/oRTww+pNs=; b=pl4aK7BGdMt/EuU+2jsjj2mc4soDYj75VgBQtGALIsJC+cRxGOff3I73rq+oySSFKX KTt6uCNiY2/lHP4v3aTsf8dQggHowJYk+5IalGKd5+klnGrti3RtIJnxndaeMAb3xB9G E/feqU7JJOOH2Biqxr7g4GEM7JZ7REBzQDe4qe8adlq3jiMF22HzG9NAMwjcA8f6btlk Ny7Vk+ChRQc3syyxglJKcTMK0jbfGDq7wa4z5uxYzwhQxb8YizX1wwHvixa+bIFyALB6 MovuAaZ4K9UbHfEG3mQsStELCBxQH+j3X13mt0v6irfmV41uubL7E4MKXiBCLuWLAQ0+ F1Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2iV6RCge; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd11si24581219plb.184.2019.07.29.12.58.51; Mon, 29 Jul 2019 12:59:06 -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; dkim=pass header.i=@kernel.org header.s=default header.b=2iV6RCge; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403982AbfG2TyZ (ORCPT + 99 others); Mon, 29 Jul 2019 15:54:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:46786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390989AbfG2TyK (ORCPT ); Mon, 29 Jul 2019 15:54:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B49C32054F; Mon, 29 Jul 2019 19:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430050; bh=rHm3w1s+OA3vgn6UbbqNpJH1RefhjVI02EjHY1GJZcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2iV6RCgeHS6+M27njPBltpyfnwTh+bjdCaf7SbuVboNzVuv+dW8KI3s+eikCo0zdo NfqXGx/ZdrRnpmiRNsy1/JtRelcJXlreE45UQKg8KPOQ3bTk2wezGTZo/VfPUPcBKo GRrzLllwoMHrhlf5mhYl97466XiXjIjyGlx9vcKc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ondrej Mosnacek , Kees Cook , Paul Moore Subject: [PATCH 5.2 180/215] selinux: check sidtab limit before adding a new entry Date: Mon, 29 Jul 2019 21:22:56 +0200 Message-Id: <20190729190811.251798429@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ondrej Mosnacek commit acbc372e6109c803cbee4733769d02008381740f upstream. 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. Cc: stable@vger.kernel.org Fixes: ee1a84fdfeed ("selinux: overhaul sidtab to fix bug and improve performance") Signed-off-by: Ondrej Mosnacek Reviewed-by: Kees Cook Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/ss/sidtab.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/security/selinux/ss/sidtab.c +++ b/security/selinux/ss/sidtab.c @@ -286,6 +286,11 @@ static int sidtab_reverse_lookup(struct ++count; } + /* bail out if we already reached max entries */ + rc = -EOVERFLOW; + if (count >= SIDTAB_MAX) + goto out_unlock; + /* insert context into new entry */ rc = -ENOMEM; dst = sidtab_do_lookup(s, count, 1);