From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E5F5C7618E for ; Tue, 23 Jul 2019 12:30:49 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id CC978223A1 for ; Tue, 23 Jul 2019 12:30:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC978223A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-16552-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 1746 invoked by uid 550); 23 Jul 2019 12:30:36 -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: Received: (qmail 16268 invoked from network); 23 Jul 2019 06:49:08 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S8rFK+AmzSO6vqLaQ/7uOy+cqgQKBpkWkT02u2erFgg=; b=drls8++j8WiIUBszZciGsgJyjRs7RIjaroezVV5U4hhoQVJNDBd42/uLtT11dOYmgk o6gOooLeD8/8CMkOWReLYf8ulQR5fa1/SIVFlN61gOJoU9X9jgwsTidiGCoMqTrmMajx PeoMCs942IopI+MGsMG3rYyXZRB+0HMAkWqyvs6FmBvflZALK0QNWkCdlLOidz+5vM1O jSVNBhUukh5v1hg39ipoOPUdN5sYtLb40WV7jhnq/sFm7XsauI+gBPpMz4LGAfkPBubZ FWj0cCIcPWyYFfpWxL8LZsgO1iQ3IsXNFpS4D7XJaBxFEhf0VJhDamVsZPtbAnAC3eSs QHag== X-Gm-Message-State: APjAAAWUIFX3GSbYxfpQ6qZm01If736q+uvJexjXTtkFjqQns5GWF41w JZc2yxP53kKFUoCdsoqpdMTRneAPJ3ygm8UWqDvZxg== X-Google-Smtp-Source: APXvYqyiqKYY0HE59VWbxE4FrpnxvD4NxAFiDhK5ANqxW/V63mYbnrK3mDoxN/AJVxU9xTHF4Q5EToDReX9NcyoLjKc= X-Received: by 2002:a9d:4c17:: with SMTP id l23mr10332937otf.367.1563864536429; Mon, 22 Jul 2019 23:48:56 -0700 (PDT) MIME-Version: 1.0 References: <20190722132111.25743-1-omosnace@redhat.com> <201907220949.AFB5B68@keescook> In-Reply-To: <201907220949.AFB5B68@keescook> From: Ondrej Mosnacek Date: Tue, 23 Jul 2019 08:48:45 +0200 Message-ID: Subject: Re: [PATCH] selinux: check sidtab limit before adding a new entry To: Kees Cook Cc: SElinux list , Paul Moore , NitinGote , kernel-hardening@lists.openwall.com, Linux Security Module list Content-Type: text/plain; charset="UTF-8" On Mon, Jul 22, 2019 at 6:50 PM Kees Cook wrote: > On Mon, Jul 22, 2019 at 03:21:11PM +0200, Ondrej Mosnacek wrote: > > 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 > > Is this reachable from unprivileged userspace? > > > --- > > 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) > > Do you want to use >= here instead? Makes sense. Also staged for v2. > > -Kees > > > + goto out_unlock; > > + > > /* insert context into new entry */ > > rc = -ENOMEM; > > dst = sidtab_do_lookup(s, count, 1); > > -- > > 2.21.0 > > > > -- > Kees Cook Thanks, -- Ondrej Mosnacek Software Engineer, Security Technologies Red Hat, Inc.