Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4361830pxj; Tue, 8 Jun 2021 12:25:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2jD6iedpi/N6cT4yqehvcA9ZGFPbgU8XsO3usglxV09WF9iuDDvjSrmKbDsC6MFhy3mGA X-Received: by 2002:a17:906:26ce:: with SMTP id u14mr24573699ejc.187.1623180307767; Tue, 08 Jun 2021 12:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623180307; cv=none; d=google.com; s=arc-20160816; b=1Io6AT6vYldzra3E6chfHoRa0m35gdOo2sENUA7+FqQUXDuSX2sc+Fcv+88VCSjccj ytXLu8NxtqmIVfwmyH//GC+sqQKCwjVH8O0z0T6DVxzvZLfPmQLVHJUmkNIPGrbaRRT6 Ux1DtNsZbfNH3oBl4z/wuVJjZDFZBNk0IB/yLxvPWvPQZVT7Fe9+cplk5fc1HRI9CRLr APSbybY+hEbFeO51V+0SmCEwD7EB8E62dfesG4lEhcE0PhOcK+nWGVccB85EqxfKExVd FGJ73LDM4PU/+s3O7mIQdsNa7WRqjIJpz1JtzYbRFYSoQ1QYKq4O8U31CfbzMWmUeEr0 +aYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+k0iwuff5PdIXh9XKEFb1yvr1MNmpQ4i/erkKKgaos8=; b=PRF7N1ilKxPPeUCC12GLjvSrx8K0HGp139pnNTLJCZR0BSRJRJVib0mz2L7vZXXtea mL0j7vDPT25ZmzKZWl5+Jw7kXs20UDRUAfhWqVw2HQK5dKIUcvZVUts1tcohM6gaTO74 FbewvwlGqBxi/egbYUfDl+rK/woqM4NxZjilFNpH7fHqN7oz+GdyOPjsnSmmAjL2Sc2V rBWmSSBxlf0EzNh7MY16XFaFrXrWe0oZXLZmEoUzBIL+86uu17E+EyY61LOYXrSbbRVu bP3l4q8jI2yyHoc9gLiXOZv9zKfLihT9kCYpC7I5hgajU0FONcvE+oWDoBjo+JV1ic+K mSpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0gMUhqWs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kl25si411965ejc.370.2021.06.08.12.24.41; Tue, 08 Jun 2021 12:25:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0gMUhqWs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237411AbhFHTWh (ORCPT + 99 others); Tue, 8 Jun 2021 15:22:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:55066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237627AbhFHTKK (ORCPT ); Tue, 8 Jun 2021 15:10:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8FC2A6145C; Tue, 8 Jun 2021 18:48:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178113; bh=fOTntlodeGdHuMj2Xfi62mHPZ9bAqwVHi0QYCJLI8SE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0gMUhqWs3DZOvSXWRKj9QMmJqvD4i6mhUL0gHgQKBYYvjhOenOTFkW7wNtNbxQLRY SMGN18bd0Q8H404ZY3/IE9LOU1ZFKI2bsjTK6R1ROE/ve+IJDvBwn7VoRr7VJ8Ppc2 SnJ8CdEAiLFoOmMzQDpOBbnyilMACTteJwa89VNc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Maloy , Hoang Le , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 080/161] tipc: fix unique bearer names sanity check Date: Tue, 8 Jun 2021 20:26:50 +0200 Message-Id: <20210608175948.147832149@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hoang Le [ Upstream commit f20a46c3044c3f75232b3d0e2d09af9b25efaf45 ] When enabling a bearer by name, we don't sanity check its name with higher slot in bearer list. This may have the effect that the name of an already enabled bearer bypasses the check. To fix the above issue, we just perform an extra checking with all existing bearers. Fixes: cb30a63384bc9 ("tipc: refactor function tipc_enable_bearer()") Cc: stable@vger.kernel.org Acked-by: Jon Maloy Signed-off-by: Hoang Le Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/tipc/bearer.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 1090f21fcfac..0c8882052ba0 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -255,6 +255,7 @@ static int tipc_enable_bearer(struct net *net, const char *name, int bearer_id = 0; int res = -EINVAL; char *errstr = ""; + u32 i; if (!bearer_name_validate(name, &b_names)) { errstr = "illegal name"; @@ -279,31 +280,38 @@ static int tipc_enable_bearer(struct net *net, const char *name, prio = m->priority; /* Check new bearer vs existing ones and find free bearer id if any */ - while (bearer_id < MAX_BEARERS) { - b = rtnl_dereference(tn->bearer_list[bearer_id]); - if (!b) - break; + bearer_id = MAX_BEARERS; + i = MAX_BEARERS; + while (i-- != 0) { + b = rtnl_dereference(tn->bearer_list[i]); + if (!b) { + bearer_id = i; + continue; + } if (!strcmp(name, b->name)) { errstr = "already enabled"; NL_SET_ERR_MSG(extack, "Already enabled"); goto rejected; } - bearer_id++; - if (b->priority != prio) - continue; - if (++with_this_prio <= 2) - continue; - pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", - name, prio); - if (prio == TIPC_MIN_LINK_PRI) { - errstr = "cannot adjust to lower"; - NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); - goto rejected; + + if (b->priority == prio && + (++with_this_prio > 2)) { + pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", + name, prio); + + if (prio == TIPC_MIN_LINK_PRI) { + errstr = "cannot adjust to lower"; + NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); + goto rejected; + } + + pr_warn("Bearer <%s>: trying with adjusted priority\n", + name); + prio--; + bearer_id = MAX_BEARERS; + i = MAX_BEARERS; + with_this_prio = 1; } - pr_warn("Bearer <%s>: trying with adjusted priority\n", name); - prio--; - bearer_id = 0; - with_this_prio = 1; } if (bearer_id >= MAX_BEARERS) { -- 2.30.2