Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1168820ybi; Fri, 21 Jun 2019 15:26:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHiY6635i8E/qY+7hED9l/A6kQGYPEJCDvodOVGCioxlkOCMUt++mvSZoum+PWG1W//HtR X-Received: by 2002:a17:902:2a68:: with SMTP id i95mr136046181plb.167.1561155982445; Fri, 21 Jun 2019 15:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561155982; cv=none; d=google.com; s=arc-20160816; b=bpKjlrjzmdTOBdxetd34v3hoS+4OLVzXKT44Evi9MUnxhE7gSAWPcsU47ANtexBabe TvWpQrrKSa9PVwh+w/gTpz9zG24sN0RXVRP12YlSwbNTcXOfioAlEhCvJZH4zF4AAG5/ QfriRdWEucM+IpxAY74ubffiYy/lDvHiQdrrJtE3ynESvKjfKYQ+soHf0P8yq4HzwI1b cVcVmOd9xiLFm5TJOuWRT4kTPnXf8qy5UFk3b53UiEywoYmkDjtx4ymroKsCLTrnFQl8 bDS5+kQ9+zrMRKN3zSW1Oe7ETfS7fOiI1j0qOJBumdsEPTjPN47LIV/tqHhzQiT5leUX 7mjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=DWIfKY3sHhlypxieTHXlR0ue9pX61XiXTJFQC3OO8/Y=; b=txntOaG4N3NTSGqxs2KDES9zrB4NXSRgkqcT7obYWYipFj84qJo2wKQpTIAUQLGnmA Xe4Ss82nl6fA2lBJ5bN+CwNIFroSOQ7Lt7e/DHd3ljAnsAA2a8se4tA/9kqhU0/eG996 wpJYPYNvk1gvaW/Z7u7+xkdfDjEklwc/vz77VJMpMmeGRG+uX6Wffh7oyzXWMGj3Gwb/ GTw912PfVMiHhCeh9VwUoxcFyMOHkDcqxI5sdhjV2h3RV2iYnrS0ZuuyHMBcuKgVXG6R HGF3AeKi18OfSskOm51X8jBHwzH3cLZYIf8MY4vv1LGigtBG3xHM+9IGtkYGdcj6owbP CdGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=F3oK9ItC; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g24si3525911pgj.197.2019.06.21.15.26.06; Fri, 21 Jun 2019 15:26:22 -0700 (PDT) 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=@chromium.org header.s=google header.b=F3oK9ItC; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726099AbfFUW0D (ORCPT + 99 others); Fri, 21 Jun 2019 18:26:03 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40827 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726052AbfFUW0D (ORCPT ); Fri, 21 Jun 2019 18:26:03 -0400 Received: by mail-pl1-f194.google.com with SMTP id a93so3656455pla.7 for ; Fri, 21 Jun 2019 15:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DWIfKY3sHhlypxieTHXlR0ue9pX61XiXTJFQC3OO8/Y=; b=F3oK9ItCKHZWlvyXbWlgudvY62RgLBcpeWB0uDFSBVHAlndEsOKy2T4/ZemmpzvRqZ oY3KQbbuu9yaU9lrznY9Dnf+cVQ2In6REloEYX5Xo4pr9Ou4thXc69h3cdaS5PSnSkPM zBpg3DUoPZ/x/EWtz1v8KcgnKa4rBKvX9hGOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DWIfKY3sHhlypxieTHXlR0ue9pX61XiXTJFQC3OO8/Y=; b=SYXmdiXLLwwMN7qKG5Dn5odOmyGniQFZwLOArjREBS0qC0YIFauvquTiS4ej3RC0Fz fJtEWIkWKM3dsTuvszQnKaQKM0hHtimstFtQJpbBh8UKx8FCRgKllLF5gmLz99nY1li/ l0Gnv9tIKBYvNnnQ1YtW7Xxjdaqyc7pd+5mv459HzOmJW00EYO+6YIPO0+dWjB6A/WOe FQtN4FrPVEy9JpHaoHtp0WxV8/VJEJHRf3SKBCqDOHnaDS34BmJwhCR3s6y9tJnJKUUV CkfmrqBSdDNgRAz1k1kGzhR0KtQo0mQSl/XaGd42XKpepLKpZDY+3G9qYhRhXcwrWy3N zXPg== X-Gm-Message-State: APjAAAW1gm+tgEDnXAZ49Ba1giSZac1qTRsRZ+p0rcaUW/66fsTlDrAL 6WIGjvAWnW89gz83e7SAFHZRbQ== X-Received: by 2002:a17:902:9041:: with SMTP id w1mr121282560plz.132.1561155962449; Fri, 21 Jun 2019 15:26:02 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m12sm3282622pgj.80.2019.06.21.15.26.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Jun 2019 15:26:01 -0700 (PDT) Date: Fri, 21 Jun 2019 15:26:00 -0700 From: Kees Cook To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/16] nfsd: escape high characters in binary data Message-ID: <201906211431.E6552108@keescook> References: <1561042275-12723-1-git-send-email-bfields@redhat.com> <1561042275-12723-9-git-send-email-bfields@redhat.com> <20190621174544.GC25590@fieldses.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190621174544.GC25590@fieldses.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 21, 2019 at 01:45:44PM -0400, J. Bruce Fields wrote: > I'm not sure who to get review from for this kind of thing. > > Kees, you seem to be one of the only people to touch string_helpers.c > at all recently, any ideas? Hi! Yeah, I'm happy to take a look. Notes below... > > --b. > > On Thu, Jun 20, 2019 at 10:51:07AM -0400, J. Bruce Fields wrote: > > From: "J. Bruce Fields" > > > > I'm exposing some information about NFS clients in pseudofiles. I > > expect to eventually have simple tools to help read those pseudofiles. > > > > But it's also helpful if the raw files are human-readable to the extent > > possible. It aids debugging and makes them usable on systems that don't > > have the latest nfs-utils. > > > > A minor challenge there is opaque client-generated protocol objects like > > state owners and client identifiers. Some clients generate those to > > include handy information in plain ascii. But they may also include > > arbitrary byte sequences. > > > > I think the simplest approach is to limit to isprint(c) && isascii(c) > > and escape everything else. Can you get the same functionality out of sprintf's %pE (escaped string)? If not, maybe we should expand the flags available? * - 'E[achnops]' For an escaped buffer, where rules are defined by * combination * of the following flags (see string_escape_mem() for * the * details): * a - ESCAPE_ANY * c - ESCAPE_SPECIAL * h - ESCAPE_HEX * n - ESCAPE_NULL * o - ESCAPE_OCTAL * p - ESCAPE_NP * s - ESCAPE_SPACE * By default ESCAPE_ANY_NP is used. This doesn't cover escaping >0x7f and " and \ And perhaps I should rework kstrdup_quotable() to have that flag? It's not currently escaping non-ascii and it probably should. Maybe "ESCAPE_QUOTABLE" as "q"? -- Kees Cook