From owner-svn-src-stable@freebsd.org Fri Oct 11 18:05:07 2019 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 120271571E7; Fri, 11 Oct 2019 18:05:07 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46qbTG6hBBz3PlB; Fri, 11 Oct 2019 18:05:06 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C8B0B1DF17; Fri, 11 Oct 2019 18:05:06 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9BI56ou033866; Fri, 11 Oct 2019 18:05:06 GMT (envelope-from eugen@FreeBSD.org) Received: (from eugen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9BI56Bk033865; Fri, 11 Oct 2019 18:05:06 GMT (envelope-from eugen@FreeBSD.org) Message-Id: <201910111805.x9BI56Bk033865@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eugen set sender to eugen@FreeBSD.org using -f From: Eugene Grosbein Date: Fri, 11 Oct 2019 18:05:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r353445 - stable/11/lib/libnetgraph X-SVN-Group: stable-11 X-SVN-Commit-Author: eugen X-SVN-Commit-Paths: stable/11/lib/libnetgraph X-SVN-Commit-Revision: 353445 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Oct 2019 18:05:07 -0000 Author: eugen Date: Fri Oct 11 18:05:06 2019 New Revision: 353445 URL: https://svnweb.freebsd.org/changeset/base/353445 Log: MFC r347439 by markj: Atomically update the global gMsgId in libnetgraph. Otherwise concurrently running threads may inadvertently use the same token for different messages. Preserve the behaviour of disallowing negative message tokens, but allow a message token value of zero since this simplifies the code a bit and tokens are documented to be non-negative. PR: 234442 Modified: stable/11/lib/libnetgraph/msg.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libnetgraph/msg.c ============================================================================== --- stable/11/lib/libnetgraph/msg.c Fri Oct 11 17:23:23 2019 (r353444) +++ stable/11/lib/libnetgraph/msg.c Fri Oct 11 18:05:06 2019 (r353445) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -51,7 +52,7 @@ __FBSDID("$FreeBSD$"); #include "internal.h" /* Next message token value */ -static int gMsgId; +static _Atomic(unsigned int) gMsgId; /* For delivering both messages and replies */ static int NgDeliverMsg(int cs, const char *path, @@ -72,9 +73,7 @@ NgSendMsg(int cs, const char *path, memset(&msg, 0, sizeof(msg)); msg.header.version = NG_VERSION; msg.header.typecookie = cookie; - if (++gMsgId < 0) - gMsgId = 1; - msg.header.token = gMsgId; + msg.header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; msg.header.flags = NGF_ORIG; msg.header.cmd = cmd; snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); @@ -143,9 +142,7 @@ NgSendAsciiMsg(int cs, const char *path, const char *f /* Now send binary version */ binary = (struct ng_mesg *)reply->data; - if (++gMsgId < 0) - gMsgId = 1; - binary->header.token = gMsgId; + binary->header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; binary->header.version = NG_VERSION; if (NgDeliverMsg(cs, path, binary, binary->data, binary->header.arglen) < 0) {