Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp228884pxb; Wed, 4 Nov 2020 20:52:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+vDaIJHz3aEiW8DnEqZbQVB/Xzwajdw22es8bgFfjEu57Ido19MzU+Eg77OnnmA9Rm5Jt X-Received: by 2002:a17:906:5a96:: with SMTP id l22mr528212ejq.303.1604551935201; Wed, 04 Nov 2020 20:52:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604551935; cv=none; d=google.com; s=arc-20160816; b=N9OAyvLJDEVmt0V7NJUq2HkBlgdZdlr+H0Fe98JzL4Du4fl2EZOVng0h+WOwTxSx17 fhsPgriD1+wVr6W8CIwUavUnkp+KKW5IB2IIX284kVO/d/3P4+nEEqVGYBpqR3jiWii8 6NSpgo9/rF13be8DSK3h3p1duyUY3w78pmIaFuhEkSQUAm37mLZb35X4ABhalLbfopZP NkrJptg5vwSHheojy4GUz/OJ8uHsEUCStvxVSid20T63x8KwJR1sabuX7hT4KvHRAF2F Zp8KvfoYq4sLMOS40Axl6C1sc3W7zKMTEXZ9mE03KuvWU763d4z2GWjkZ0IDQ1sUftfD HFsg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=hgGjVTTMyQ2M6dgmkNIb7vTvWhzzwCqkk8tLANTN3tM=; b=qCNE4TMEUTDUqZw6eoljOrI4eHEUGF6gvwg2KXlG8ZfGB9BgH0ZJJDy5jL1ye6Cg4n NY7D52bbKpW1aI/1ElbHUxFeBzYNWdOWjAoqw3GVUpAwOo96ETT882ptNB/dDVim1O7L aU6MEmrMJr7L7q3rCt47PmATo1JL36bgXsW03i280WzpxdYhilrTaDWrY/aNXkxVRpHP 6Zw9XmZIO2bMH4yHJ4TlgyL7DpVzMCyAX5TF0duhzF96dLQ6DwRCNYdE948K6dwCrRoI Kwyta4ayQSvGQ+zX6FJIvP2Tf+CdjQnq5r8qdIBnS23B0cGNAtZbtpHrFpPpkcp/BMT+ oZEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm1 header.b=AlohzBKg; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=RhHsiIyJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lx2si331083ejb.316.2020.11.04.20.51.52; Wed, 04 Nov 2020 20:52:15 -0800 (PST) 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=@dxuuu.xyz header.s=fm1 header.b=AlohzBKg; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=RhHsiIyJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387576AbgKEC0I (ORCPT + 99 others); Wed, 4 Nov 2020 21:26:08 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:34633 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbgKEC0I (ORCPT ); Wed, 4 Nov 2020 21:26:08 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E44BE5C006F; Wed, 4 Nov 2020 21:26:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 04 Nov 2020 21:26:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=hgGjVTTMyQ2M6dgmkNIb7vTvWh zzwCqkk8tLANTN3tM=; b=AlohzBKgqvEmuR9NLV0Hma4CpSlClNx5iXiZI+OLFn kh+qKtOXCZdqu+0FZnS0MUHhHS5OLtWzr0dNgzyoru33ynZoCY1aTAbN2je7TGaW HQO24PU3V4Wdc4SN4KPenjLs5Ll8IpapCaWKJ/9cNdKEYKNO858HSh2DGpFdDaHS MTgZEmm8pm4K3ICEKrR+DXDlMIGhUYhZ3Ltd0KdBUVvJHiU9F566GoDZ03gIMVZa bXJXr+Bo8YQTCwuwE5b+oQlip2YtZcC0pl91C0TCIx+qgpmo86AFnlFp615gF4X8 hVgk7FjE94MexrzdKN9NUusQrgEw4o+61aku8kECMt8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=hgGjVTTMyQ2M6dgmk NIb7vTvWhzzwCqkk8tLANTN3tM=; b=RhHsiIyJ9qOEOLktr13mM5HdaJubYEfDd ik6tvR8l+Ytp7xuNg7ZIo7ePAPYveMd+THe8TnTg4vCOZsiOvkkectqYNnLfT0/X iWrldAuLR75Dn/f3IM/zt2iXVMPATBj6nOClxd6dZ1lty9kYckfj9wwT7qBNP0kB bi68z2HPcGpcwQ9wonnrkV5fo/kp2cNkPaWOqqQscpiIwjgI7qRNMy6M13GFlh0c EpJWndK86Hspj9JkyaGmrxSK7umgKJW0AN+0OztRS3yrLBSNaQ3PpsibPo1J49pk TqhtnevexoBkyyvvTHV0/5UeB3QnkELhD9esjfo20jGdxDdTongWQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddtiedggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf fufffkofgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihu segugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpeeifffgledvffeitdeljedvte effeeivdefheeiveevjeduieeigfetieevieffffenucfkphepieelrddukedurddutdeh rdeigeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gugihusegugihuuhhurdighiii X-ME-Proxy: Received: from localhost.localdomain (c-69-181-105-64.hsd1.ca.comcast.net [69.181.105.64]) by mail.messagingengine.com (Postfix) with ESMTPA id 130F33280222; Wed, 4 Nov 2020 21:26:06 -0500 (EST) From: Daniel Xu To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: Daniel Xu , kernel-team@fb.com Subject: [PATCH bpf v2 0/2] Fix bpf_probe_read_user_str() overcopying Date: Wed, 4 Nov 2020 18:25:36 -0800 Message-Id: X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 6ae08ae3dea2 ("bpf: Add probe_read_{user, kernel} and probe_read_{user, kernel}_str helpers") introduced a subtle bug where bpf_probe_read_user_str() would potentially copy a few extra bytes after the NUL terminator. This issue is particularly nefarious when strings are used as map keys, as seemingly identical strings can occupy multiple entries in a map. This patchset fixes the issue and introduces a selftest to prevent future regressions. Daniel Xu (2): lib/strncpy_from_user.c: Don't overcopy bytes after NUL terminator selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL lib/strncpy_from_user.c | 9 ++- .../bpf/prog_tests/probe_read_user_str.c | 60 +++++++++++++++++++ .../bpf/progs/test_probe_read_user_str.c | 34 +++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/probe_read_user_str.c create mode 100644 tools/testing/selftests/bpf/progs/test_probe_read_user_str.c -- 2.28.0