Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4837845pxj; Wed, 9 Jun 2021 03:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJKqTbCkN51bHRRFCnKNmf1hsztFHdxkb7JoXM3LAtbVnIuAEWdp1VmWy3B31+Fuy8jk4G X-Received: by 2002:a17:906:1dc2:: with SMTP id v2mr28185811ejh.8.1623233401938; Wed, 09 Jun 2021 03:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623233401; cv=none; d=google.com; s=arc-20160816; b=j4hse5ayx29jkwVzDiMD/DcABRn99HNmiHx2C0FBFk7JBwHBbvbjadX0btV4wnRqsX gkZHARNLVQs84QICNSW3ns4mjJW8y1nZfmYkWGwBKV1AJooMiwPOu2LRg8QBrYxOPcE/ dDHWPSeIfixeXoBdjPjHee9SGFQzny2JjT2ssTpOfEXam8UGqv+0Lokw6PAN+8AvbIXH b4R0hNOQ79eQjnRnxtKRc5udEKY3oo+WmQ/oPeFswbpTr4v13acE4HVKse4g/kW90lJu gMLVFLUjWfR8uD8Vdr0m0fLddrEz5aFE3TxwunUSUfad8XcHTbncqcvqPVbdkpq9ZfxQ LyTw== 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=oE4fub2FFhKNLitKyy8ZQifOJKkOPao8fsSPXfCI2s4=; b=j06/IroIzrc4+M84qpkgtrkhLX7RJsB9XKi4rqX33lrtGoV9WP/aE58dCiPwopiGRC Wq4+eNXSQyB7yHYO6Q6VfH+S3ahR7ogGU9yQqZ3HTfnsKzsU8p7usHvmrej0EoSFn2bz L8L190Aax7exxK+Dg3j6Um3qx1nW84QNqc1ZQbduXWkABImZ/H0HKxNjWF5lwwBM2Enf mUPGpWHWKo3YhzF1C9rRpZ5y9ga4sB2pPXQQRofPyJg/v5AqSHdnR4e/LTZ4zU6Cbd+c GnrEoVtGQ8Grv6DEGz58wO8Ucrzt61q8eRY97Bb91J8ryzvWzTbpJO8NzB9W724+xA1A g/wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GNktrnDk; 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 p16si2257202ejn.173.2021.06.09.03.09.38; Wed, 09 Jun 2021 03:10:01 -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=GNktrnDk; 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 S236482AbhFHSyU (ORCPT + 99 others); Tue, 8 Jun 2021 14:54:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:47360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234036AbhFHSsJ (ORCPT ); Tue, 8 Jun 2021 14:48:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A5F26145D; Tue, 8 Jun 2021 18:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177492; bh=C1gEFeTRKQbm9RMBtjmkF4x50MUnzmfOAp+V72z9Iyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GNktrnDkaQ2mydjUgN70L0MemcrUSyxk0lQ/WpTj/PI29ipKCgP6H9RH+8uRGB6ou 9/oi+A8arNUzBIK+ZshTSMQNQRbWt1iL5MIiPoC3nM6rqOmidYQxvWmG7rFhEZeY/8 +tKOeqn1xUsnH08NWrOhqv3O9VogAFZHqguAISSg= 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.4 37/78] tipc: fix unique bearer names sanity check Date: Tue, 8 Jun 2021 20:27:06 +0200 Message-Id: <20210608175936.513145213@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@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 0e0161597749..8bd2454cc89d 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -245,6 +245,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"; @@ -269,31 +270,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