From patchwork Wed Jan 24 16:00:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 125679 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp505039ljf; Wed, 24 Jan 2018 08:01:04 -0800 (PST) X-Google-Smtp-Source: AH8x224Z/ljiGzRoJvny9U53N+9VkGUzuEIkq0Kkm928EHeGmdIeyQPHmls2TrAgviO202S2dcuz X-Received: by 10.37.22.195 with SMTP id 186mr5652709ybw.300.1516809664305; Wed, 24 Jan 2018 08:01:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516809664; cv=none; d=google.com; s=arc-20160816; b=sfOrD18X1n+j1Ej5ELLXuZ+CPYzTSNaNV+O8qKOMaZfhRr5MhiosoHSwrvVRoPAATu vJaEQsMKt8h95tioJwnNKE1K1Osjf4fVJVAQHYaD3SSZU51SJK9yOOk0bbUnxcOh0KEb hf2eP53y/xIbMjU6G6Jj5PsQpqa0JMaJ/uT0igr0baGUw15OT3sHqAdX//qmNfgIatB9 79CmbEH6LhDHXVeLGoyVXXbwCeqrARYE5sSBWohyzo0crE+B6Bb+uc5qvKv8HDQbgEiM HJYie0sGHYI+5eEjtUQe6RvlrsjnXZKJOip8yzZf2IQawW3BPx3XTymgW2bR/TNbkYGZ mWcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=utuEOADrGUGHTuo+jxuBceB6x0bGi6j9Fh17sF+BgCY=; b=DwPAk7CcjFe078xrVs0ncEf2Ft8QaESBKxkYqKvZAKArRqR/HYA701WGNLA+c/Cuc3 eoS+X0+WQOjkkhu22LH+P1vHoQK3Iz6cHWTExVzqpZr7oxfCqHc0wF4Pq0Q8D0IZt6gf CoSoNhTBUk0Cvo5iNUxV585EISjQlgsdaYxIOBNiPibiE99YPNQpmjEQSV9lCehnR+9X QKOB7kDTNk3qTcboIn+5/c8ixlCY36hQF+d6HvcKgwaud4gZ6/Dnqxnv7PiJunduY5oe lBXKCXtrr7qZLjcDqiU56b58cO2xE2bDoyvlCJy3aI2G/JSgDTJfHMVvt1WV1bVB2G81 rMrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id c78si519331qkj.158.2018.01.24.08.01.04; Wed, 24 Jan 2018 08:01:04 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id EA9A361726; Wed, 24 Jan 2018 16:01:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 896F561760; Wed, 24 Jan 2018 16:00:27 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 76ED560B04; Wed, 24 Jan 2018 16:00:17 +0000 (UTC) Received: from forward106j.mail.yandex.net (forward106j.mail.yandex.net [5.45.198.249]) by lists.linaro.org (Postfix) with ESMTPS id 18F056081B for ; Wed, 24 Jan 2018 16:00:12 +0000 (UTC) Received: from mxback1g.mail.yandex.net (mxback1g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:162]) by forward106j.mail.yandex.net (Yandex) with ESMTP id 36606180508F for ; Wed, 24 Jan 2018 19:00:10 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id TpnVOJAdtL-0AMewYvQ; Wed, 24 Jan 2018 19:00:10 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Q8SBLojAvI-09sKqS4v; Wed, 24 Jan 2018 19:00:09 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 24 Jan 2018 19:00:05 +0300 Message-Id: <1516809608-18061-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516809608-18061-1-git-send-email-odpbot@yandex.ru> References: <1516809608-18061-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 427 Subject: [lng-odp] [PATCH v1 1/4] linux-gen: ipsec: disallow using SAs while they are being created X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Current code has a race condition between inbound traffic and creation of new SA. It is possible for inbound traffic to trigger partially created SA using SA_LOOKUP option (or INLINE mode). Add separate (RESERVED) stage for SA which is in process of being created. Fixes: https://bugs.linaro.org/show_bug.cgi?id=3594 Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 427 (lumag:ipsec-fix-sad) ** https://github.com/Linaro/odp/pull/427 ** Patch: https://github.com/Linaro/odp/pull/427.patch ** Base sha: 27480d82bd93a881ae683a3c314c11042a68ce29 ** Merge commit sha: 83482dc460d8a076de317029373e2c8bf3178974 **/ platform/linux-generic/odp_ipsec_sad.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/odp_ipsec_sad.c b/platform/linux-generic/odp_ipsec_sad.c index 845a73dea..bb984db38 100644 --- a/platform/linux-generic/odp_ipsec_sad.c +++ b/platform/linux-generic/odp_ipsec_sad.c @@ -17,7 +17,8 @@ #include #define IPSEC_SA_STATE_DISABLE 0x40000000 -#define IPSEC_SA_STATE_FREE 0xc0000000 /* This includes disable !!! */ +#define IPSEC_SA_STATE_FREE 0xc0000000 +#define IPSEC_SA_STATE_RESERVED 0x80000000 typedef struct ipsec_sa_table_t { ipsec_sa_t ipsec_sa[ODP_CONFIG_IPSEC_SAS]; @@ -108,7 +109,8 @@ static ipsec_sa_t *ipsec_sa_reserve(void) ipsec_sa = ipsec_sa_entry(i); - if (odp_atomic_cas_acq_u32(&ipsec_sa->state, &state, 0)) + if (odp_atomic_cas_acq_u32(&ipsec_sa->state, &state, + IPSEC_SA_STATE_RESERVED)) return ipsec_sa; } @@ -120,6 +122,12 @@ static void ipsec_sa_release(ipsec_sa_t *ipsec_sa) odp_atomic_store_rel_u32(&ipsec_sa->state, IPSEC_SA_STATE_FREE); } +/* Mark reserved SA as available now */ +static void ipsec_sa_publish(ipsec_sa_t *ipsec_sa) +{ + odp_atomic_store_rel_u32(&ipsec_sa->state, 0); +} + static int ipsec_sa_lock(ipsec_sa_t *ipsec_sa) { int cas = 0; @@ -128,9 +136,11 @@ static int ipsec_sa_lock(ipsec_sa_t *ipsec_sa) while (0 == cas) { /* * This can be called from lookup path, so we really need this - * check + * check. Thanks to the way flags are defined we actually test + * that the SA is not DISABLED, FREE or RESERVED using just one + * condition. */ - if (state & IPSEC_SA_STATE_DISABLE) + if (state & IPSEC_SA_STATE_FREE) return -1; cas = odp_atomic_cas_acq_u32(&ipsec_sa->state, &state, @@ -438,6 +448,8 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) &ses_create_rc)) goto error; + ipsec_sa_publish(ipsec_sa); + return ipsec_sa->ipsec_sa_hdl; error: