From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S945961AbcJaTbY (ORCPT ); Mon, 31 Oct 2016 15:31:24 -0400 Received: from shards.monkeyblade.net ([184.105.139.130]:56558 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S945847AbcJaTbW (ORCPT ); Mon, 31 Oct 2016 15:31:22 -0400 Date: Mon, 31 Oct 2016 15:31:17 -0400 (EDT) Message-Id: <20161031.153117.1954668010224339938.davem@davemloft.net> To: iboukris@gmail.com Cc: stephen@networkplumber.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] unix: escape all null bytes in abstract unix domain socket From: David Miller In-Reply-To: <1477768820-1295-2-git-send-email-iboukris@gmail.com> References: <1477768820-1295-1-git-send-email-iboukris@gmail.com> <1477768820-1295-2-git-send-email-iboukris@gmail.com> X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Mon, 31 Oct 2016 11:31:44 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaac Boukris Date: Sat, 29 Oct 2016 22:20:20 +0300 > Abstract unix domain socket may embed null characters, > these should be translated to '@' when printed out to > proc the same way the null prefix is currently being > translated. > > This helps for tools such as netstat, lsof and the proc > based implementation in ss to show all the significant > bytes of the name (instead of getting cut at the first > null occurrence). > > Signed-off-by: Isaac Boukris ... > @@ -2805,14 +2805,19 @@ static int unix_seq_show(struct seq_file *seq, void *v) > > i = 0; > len = u->addr->len - sizeof(short); > - if (!UNIX_ABSTRACT(s)) > + if (!UNIX_ABSTRACT(s)) { > len--; > - else { > + for ( ; i < len; i++) > + seq_putc(seq, > + u->addr->name->sun_path[i]); > + } else { > seq_putc(seq, '@'); > i++; > + for ( ; i < len; i++) > + seq_putc(seq, > + u->addr->name->sun_path[i] ?: > + '@'); > } > - for ( ; i < len; i++) > - seq_putc(seq, u->addr->name->sun_path[i]); I think this patch is simpler if you just do the "@" translation unconditionally, if it'll never trigger for the !UNIX_ABSTRACT case that is perfectly fine.