Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3434382pxb; Mon, 16 Nov 2020 14:49:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7G/yWMI7DmIChTqA799Z7MFx+CwHKmoAwVjNLSpzYk8uAJ7qsUVNDpMriu04WOJtlsbib X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr17182838edu.243.1605566979175; Mon, 16 Nov 2020 14:49:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605566979; cv=none; d=google.com; s=arc-20160816; b=Ax/ucdlAy37pgAc9wSzFFREIqxQ196NEpkULPL028aHMyIOONT1Pul93eMygZsBHsj 3kjmrKLRzeTCvgwHnxy9pl9S2foHd+afLxoDpp1HTJhyKJjJxUW64ZDwquZgmT9oc/zE zbKpzwhmx517GI4oHWAxJgY1g6jqXgSj9ekjKMUOlbJU8d+uEBtofBxq+VSIb72R9P5l jz4SWZf4FR8uycYOTMXgg2J30nucfy/SNlUEWojutdLkA78KPAVmOgrAjPxtkYejzy84 XS1wx7VCKJDW6XzwzcFdiBJCdUFf3GfO84JezNZE6+45bR+7WR0ns7mSZqMUKdOoNiKB 3dCw== 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=bI7+0n+mvNdYBFFyytXWs7i5PUCHOde+5ov5uwXFL7k=; b=HlnmsgRX1fFSDFUAjhD4OPkjPcCUJrGj2zMhOKy+TJBisk4spig2Hc00pr2J1DZmpU aQQDspwzrgIV9oWc3kg51wFa+XvtOr9LftUJ4uestaCy+v4O8Fodc3w0nG2R9DIK7LzX VFe6Pvw6LSLFIadbO5+g4NWyoBiVANZref5qMDDbvQu23XK0S6p8C0LAeXML6kkoJLeT 7qLHA6n8sCvCyKKTq4A/IZS8EDOW8xEr1kbpbYls76fd+xofr5Zs0vqsQRBlTIb8ErXD KykyeC5TSKwPTmaEYC4QF5YlhwgD0a8ZgMpZho8NqdgHPmZCnVhPf0Hf5Dn4u7gUlYy9 Bi0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm2 header.b=m0qOIwIJ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="CS6/vLYd"; 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 q11si11621966ejb.550.2020.11.16.14.49.16; Mon, 16 Nov 2020 14:49:39 -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=fm2 header.b=m0qOIwIJ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="CS6/vLYd"; 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 S1728298AbgKPVRx (ORCPT + 99 others); Mon, 16 Nov 2020 16:17:53 -0500 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:35305 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbgKPVRt (ORCPT ); Mon, 16 Nov 2020 16:17:49 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 35B50D05; Mon, 16 Nov 2020 16:17:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 16 Nov 2020 16:17:48 -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=fm2; bh=bI7+0n+mvNdYBFFyytXWs7i5PU CHOde+5ov5uwXFL7k=; b=m0qOIwIJXZidGxx0Mp8vuIA/REOXrKwkhn37qVDsum vQS1YupiiabxkBvRsg86kMnpmE9QV5R9C+AB/KquaJegGOSkUzkXrmNla+8W1eOh 4+k6iA02/5vQ+WreGmBkoRbAUJj2GtvXhgyWxWs08GyylHCFTlFTrM3bfGSb/EPi sfS+iS751ZS3yTKA+RKMwAWn2HM7Q9828/2trZOl67bw9EFKHUUYLCKJLm7+aZzz xcpUTMwJNR53LsNLGP9Ja1Bsva87gmFHxfp6FV+aKgD9JVpW6NdAafnbSTMfd/PE X+53l+MlfomTITB4jp2xdArf/MNE0I1Y0csYjnCZcwVQ== 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=bI7+0n+mvNdYBFFyy tXWs7i5PUCHOde+5ov5uwXFL7k=; b=CS6/vLYdbVG0YQDrNXnWM69h3YTrShaCY nEgzlL01sPxL9PKSdzMwnw9w1YtCJSHtNjbsr07Tay6nT7Wom75O9XXMHmfvF1Gt yORDUuTI1zl2c+4QMswXTqPbOUDqD4jOVXgYBqzYxRiJy6poZiKrVvcLVH5qkh2f XSHM/csNQ4xQkcJTFdNbcLlB2qSbqpZxnXkNFRtdSfwHRgRfPNNEFzSGRf0U8v5Q Hzf2bGwRwb4jG3TGqhGXiAA3chwlCh+yIMRKPicfQicAAknOGhZ2w+GPXm1qUDVJ vlBZa9g+S9KyPWq0sVrlcu8khupjdsgsh5klta1hv4e6qpAfUBX5g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefuddgudegkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephf fvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougig uhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepieffgfelvdffiedtleejvd etfeefiedvfeehieevveejudeiiefgteeiveeiffffnecukfhppeeiledrudekuddruddt hedrieegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epugiguhesugiguhhuuhdrgiihii 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 E98DF3280060; Mon, 16 Nov 2020 16:17:45 -0500 (EST) From: Daniel Xu To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, songliubraving@fb.com, andrii.nakryiko@gmail.com, torvalds@linux-foundation.org Cc: Daniel Xu , kernel-team@fb.com Subject: [PATCH bpf v6 0/2] Fix bpf_probe_read_user_str() overcopying Date: Mon, 16 Nov 2020 13:17:30 -0800 Message-Id: X-Mailer: git-send-email 2.29.2 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. v5 -> v6: * zero-pad up to sizeof(unsigned long) after NUL v4 -> v5: * don't read potentially uninitialized memory v3 -> v4: * directly pass userspace pointer to prog * test more strings of different length v2 -> v3: * set pid filter before attaching prog in selftest * use long instead of int as bpf_probe_read_user_str() retval * style changes v1 -> v2: * add Fixes: tag * add selftest 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 | 8 ++- .../bpf/prog_tests/probe_read_user_str.c | 71 +++++++++++++++++++ .../bpf/progs/test_probe_read_user_str.c | 25 +++++++ 3 files changed, 102 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.29.2