Received: by 10.223.176.5 with SMTP id f5csp799221wra; Sat, 3 Feb 2018 10:32:15 -0800 (PST) X-Google-Smtp-Source: AH8x226k1DVnITGOca8sRazGPBo+nxv1CpCrFpF8ZnhHQ8WGAyMmHN4QyckFNNWyvz7hk3zqzok8 X-Received: by 10.98.75.218 with SMTP id d87mr1812515pfj.11.1517682735313; Sat, 03 Feb 2018 10:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517682735; cv=none; d=google.com; s=arc-20160816; b=yIxHBWP1kAm2GhLrzN3CxcjIItqL1D1jGg3dVfZROPPy/CaHxSn++iaJKiR6lvM8Ss K4Wjl4hw53hbcRZqibaX0fWIaI9siSbKovm4RH36CJwGF7gw5mmJMAmYx6Elr2TPtsK3 bGjqiaU+vUqwEcLIb09s/2UwhF6tD6U4u7MBIwZv0d5osjlfGsiFYAlmZrcRWZ4o+hSb W5eikqsk7X9jqlsCxL9p5O2azsxRrRXNFfAhT2r4tAO4U5oPso44pCEiQBBr4G3XWEXu ge+ajFWCLh66QVDuBFm4rCM5CCnX8XNmaiE9GaxExRLt5VLUaEatG7MYq8UaONIBuZmX aDGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=5xqCVFrFwE543HlSqAhGfcQuH6saAstRpvJYeo2tIdI=; b=CIwpZYf8jy8HOy3z9Q4azRvmw6paluSIXhzhoZit3PB9rkoAwSppcJyY9aSeFb2Ct3 YCtIWP0d95b6u0iT5ho0sTE86Wd2aw4E+HFws6TCNpcz3Ejscmyn/BMz/P8ay5dFv5bm BSH0+igRlie4wS0bpSPaIUf1yEJ9HA+b0fvCPo958iWx+hj/BLhwfc5Ua1nLicaMvGBL M+NAXvdXGqjOKjj9TM3p6gpgUXyN8SnylctAwYGl27h1ovPrM0IAd5egAHjhZ4/j95YX OfhFZRGhdkK+abkYCc2SbP2LP8rBO7UaFGkOI6GiMKbzwsasb0XFjfNhiyxBqshigX2H Kd+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ey6ORSZq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v37-v6si4136352plg.521.2018.02.03.10.32.01; Sat, 03 Feb 2018 10:32:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ey6ORSZq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754725AbeBCSbB (ORCPT + 99 others); Sat, 3 Feb 2018 13:31:01 -0500 Received: from mail-bl2nam02on0127.outbound.protection.outlook.com ([104.47.38.127]:37417 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752688AbeBCSEr (ORCPT ); Sat, 3 Feb 2018 13:04:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5xqCVFrFwE543HlSqAhGfcQuH6saAstRpvJYeo2tIdI=; b=Ey6ORSZqrJvwEbj5LxKNodyLQzdQr0jguJ8SaajU052WqLaojjCeZQpd9kH7z1uBDU+CG5iAh0CyeaEja9O6DtrEMZcFdf4ulSSgEh3AfzrMaz1t1l4pM1zvQ2RytpwBeMzG1LwrjtpLkJyUZ9IRtnVmS5UvH03pFUbfKkdCDm8= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1041.namprd21.prod.outlook.com (52.132.23.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.3; Sat, 3 Feb 2018 18:02:47 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:02:47 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: John Fastabend , Daniel Borkmann , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 093/110] bpf: sockmap missing NULL psock check Thread-Topic: [PATCH AUTOSEL for 4.14 093/110] bpf: sockmap missing NULL psock check Thread-Index: AQHTnRkDvCnymrbU0Uqy41wVbJxB9g== Date: Sat, 3 Feb 2018 18:01:27 +0000 Message-ID: <20180203180015.29073-93-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BL0PR2101MB1041;7:lWvcmvqftcy3H0vki5Efkvb2iDs8Yu+g+KbaTUtH1TvS7HBwJm5ME9V1Sfo/KraY1UH51UTkDBsOfe1l0kSnaDmuMH8mKxhzRGsWFQF/obxiLTE/NDxGuV4XqgXPnIGd1YY8lRPlpQgoPjTKQVOx7HCej9a/Dbw9LYr5meM2++k7FFAIJduQECj9yrePkDdsLN5KKt9LnHL7at35PTQZocQq+EB9bfIwc6i9c3VjC3ZJOKCofc+6cUA71O/JfvqP x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: efb4e84d-eeea-45e2-53f5-08d56b30554e x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1041; x-ms-traffictypediagnostic: BL0PR2101MB1041: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3231101)(2400082)(944501161)(93006095)(93001095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:BL0PR2101MB1041;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1041; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(396003)(366004)(39860400002)(376002)(346002)(189003)(199004)(2501003)(305945005)(3660700001)(5250100002)(81156014)(99286004)(81166006)(36756003)(7736002)(10290500003)(106356001)(53936002)(5660300001)(316002)(22452003)(8936002)(54906003)(110136005)(3280700002)(478600001)(72206003)(4326008)(39060400002)(25786009)(107886003)(102836004)(97736004)(76176011)(59450400001)(6666003)(66066001)(6506007)(2950100002)(2900100001)(68736007)(8676002)(6116002)(3846002)(186003)(1076002)(6346003)(105586002)(26005)(10090500001)(2906002)(6512007)(86612001)(14454004)(575784001)(86362001)(6436002)(6486002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1041;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: 43N+CTZr9g3yl9Tpt9dIsJPIUw6O35M28gvB0ADmTGVht+XM2Cghc5hY2kdD6VEKAvRJz9raT5dtB5F4vCq38g== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: efb4e84d-eeea-45e2-53f5-08d56b30554e X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:01:27.7690 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1041 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Fastabend [ Upstream commit 5731a879d03bdaa00265f8ebc32dfd0e65d25276 ] Add psock NULL check to handle a racing sock event that can get the sk_callback_lock before this case but after xchg happens causing the refcnt to hit zero and sock user data (psock) to be null and queued for garbage collection. Also add a comment in the code because this is a bit subtle and not obvious in my opinion. Signed-off-by: John Fastabend Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/sockmap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index dbd7b322a86b..1890be7ea9cd 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -588,8 +588,15 @@ static void sock_map_free(struct bpf_map *map) =20 write_lock_bh(&sock->sk_callback_lock); psock =3D smap_psock_sk(sock); - smap_list_remove(psock, &stab->sock_map[i]); - smap_release_sock(psock, sock); + /* This check handles a racing sock event that can get the + * sk_callback_lock before this case but after xchg happens + * causing the refcnt to hit zero and sock user data (psock) + * to be null and queued for garbage collection. + */ + if (likely(psock)) { + smap_list_remove(psock, &stab->sock_map[i]); + smap_release_sock(psock, sock); + } write_unlock_bh(&sock->sk_callback_lock); } rcu_read_unlock(); --=20 2.11.0