Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1422246pxb; Wed, 6 Apr 2022 18:31:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7jUyGWgFs1qXsAWsVb7G1eCG5hIxxEluKliJ3erEdn1SDPsEz1xepgib8YPm+0g3tPGpA X-Received: by 2002:a17:907:1b10:b0:6e4:bac5:f080 with SMTP id mp16-20020a1709071b1000b006e4bac5f080mr11012296ejc.24.1649295099298; Wed, 06 Apr 2022 18:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649295099; cv=none; d=google.com; s=arc-20160816; b=EfwwDjwerZvQJfcs1DTRtplR75DaA/mKro6w1fXxWqUx0u4zFhBM/MljsPAz3Iu87U 6n9YFVfeaU/EbaXLNCK+THJccvSUna8wAUB2Gl+XQEVeapuL0OlffeMVlZ5DOH+64WBO 2eFuRyRW/G7r+qjyM9QK1DIRBpfz2UvIFnpjTTpY9HoXuxGdSPUI6Sz/IT8p71UytHK1 iPkqxsyAy8IWfQbfw35Rz+jRIaLBuOqdFGi4PAHGpvLz+kl99ijBGAbWLrpsrQcRidzk NznDdftQiXXVLgZBq+W7lpBjhVQvHQw8ZfrbuX5ERMpQXbRLYcNbhqCiUKPfu1SQBARA Eerg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=bXhrp57RyScu0ZRvGqkj/42ZMpBOCbed3PRNPxmdooU=; b=TcgxtlKjC4CHP49k4ab0cebR9lMivdbv3crYBmMwBZVNsTuq96GgrJricGCpxUzhp0 JtaPkXY87b5H+Ty9zsCnq+wpMxBGwa+9LrdrGNc4pfty8J5M8n2AdYy0g0s5HTH6/HyI 17FB1UK1LtNVHxxrDklcVGJ5X5Gx0Z7LjtmtBJsiCwkJoLp5KufR5wVw+fR0DEekUsuo gm+UBspXaVf49a8wVsgDwbjlcZpqLiWVgltrOg/tJEvh7f9AebvGz1GzL+LKudTEDWLN +AczmqC/wC2XJ6De5QfaEK0tfi2h+YvxZgRigQqDqN7QlW0x2cIvWqam7ckpcWXgkV// xAvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@networkplumber-org.20210112.gappssmtp.com header.s=20210112 header.b=B59yobXT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a056402430d00b0041b582ec9cdsi14024061edc.218.2022.04.06.18.31.14; Wed, 06 Apr 2022 18:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@networkplumber-org.20210112.gappssmtp.com header.s=20210112 header.b=B59yobXT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236907AbiDFWBq (ORCPT + 99 others); Wed, 6 Apr 2022 18:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236888AbiDFWBo (ORCPT ); Wed, 6 Apr 2022 18:01:44 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B42D158D8C for ; Wed, 6 Apr 2022 14:59:45 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id n6-20020a17090a670600b001caa71a9c4aso4216724pjj.1 for ; Wed, 06 Apr 2022 14:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bXhrp57RyScu0ZRvGqkj/42ZMpBOCbed3PRNPxmdooU=; b=B59yobXTGPG4rEfgZjhYoSKEU4ZMy+8G9eOxJcsAVR9eKsxs7p0WGGXtFMVpagGXNK dc4CcJaYjjpvU+9eQ0X2Lt92CL0FUiid9cd+cr9qROWyWtMhR4nXsBnAr1RaWcW0t/xq 6sVHWUttKLQi3MW8gne2IPX2vp23No3IfrWl1IC4fgtjfhybReP9L72H/uAidTrHi07x WdpxrHRw4thm/pt2GLR4yKHel6jLeLq1VWY+mFsuf0eb/46uuriT1kjp65eDBJ9uAkzM sCCE0siQIAXgyFR7MFokyn5WQbLHG5NbmhZ+zyQc2c44Xg4wNySqGtL8QRqwPiL2F4cT EkBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bXhrp57RyScu0ZRvGqkj/42ZMpBOCbed3PRNPxmdooU=; b=Uzsj178a0bb6x2yeIqIQVsgdXyAuqIijyVUfm6SsYuFOQhXUb32Dyba1QQXc+jTj2m Du1vzX8wa4DnXe8CQmptxnPdm0ZsGY+NEw8+spuCcD/FtO9s1oCFCLUlPGq5gXmssuY2 kxKTuov4psMT+d771hq3XdKF9J6w4R9ZivejzCblm1snJ7sjZr8IAKsCStVDhUEzJ9Mo F3SPYRMy9dO6cYwO1aP7ukYg22ctNxlq3C6/fILWrDyvgt8CIXqNM0504zBlZAduyApz rf/AH0QUGZaogyPYiwM6PSFjg4quA+VW76V50Z9gJ3Im1yZZvdjymn5WxKON4tZh1zLW lr2g== X-Gm-Message-State: AOAM532lOTAo1qb8GnQomtCqgJ1/u3MBAsWEAN+VDa2alE54ro/PgQpy ejOsfMYLnVVEg4xPc76QabOnwvbXPS53AQ== X-Received: by 2002:a17:902:ce05:b0:156:a7f7:aae1 with SMTP id k5-20020a170902ce0500b00156a7f7aae1mr10931690plg.166.1649282384592; Wed, 06 Apr 2022 14:59:44 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090add4300b001ca56ea162bsm6323543pjv.33.2022.04.06.14.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 14:59:44 -0700 (PDT) Date: Wed, 6 Apr 2022 14:59:41 -0700 From: Stephen Hemminger To: Yann Droneaud Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] af_unix: Escape abstract unix socket address Message-ID: <20220406145941.728b4cb5@hermes.local> In-Reply-To: <20220406102213.2020784-1-ydroneaud@opteya.com> References: <20220406102213.2020784-1-ydroneaud@opteya.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 Apr 2022 12:22:13 +0200 Yann Droneaud wrote: > Abstract unix socket address are bytes sequences up to > 108 bytes (UNIX_PATH_MAX == sizeof(struct sockaddr_un) - > offsetof(struct sockaddr_un, sun_path)). > > As with any random string of bytes, printing them in > /proc/net/unix should be done with caution to prevent > misbehavior. > > It would have been great to use seq_escape_mem() to escape > the control characters in a reversible way. > > Unfortunately userspace might expect that NUL bytes are > replaced with '@' characters as it's done currently. > > So this patch implements the following scheme: any control > characters, including NUL, in the abstract unix socket > addresses is replaced by '@' characters. > > Sadly, with such non reversible escape scheme, abstract > addresses such as "\0\0", "\0\a", "\0\b", "\0\t", etc. > will have the same representation: "@@". > > But will prevent "cat /proc/net/unix" from messing with > terminal, and will prevent "\n" in abstract address from > messing with parsing the list of Unix sockets. > > Signed-off-by: Yann Droneaud > --- > net/unix/af_unix.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c > index e71a312faa1e..8021efd92301 100644 > --- a/net/unix/af_unix.c > +++ b/net/unix/af_unix.c > @@ -3340,7 +3340,8 @@ static int unix_seq_show(struct seq_file *seq, void *v) > i++; > } > for ( ; i < len; i++) > - seq_putc(seq, u->addr->name->sun_path[i] ?: > + seq_putc(seq, !iscntrl(u->addr->name->sun_path[i]) ? > + u->addr->name->sun_path[i] : > '@'); > } > unix_state_unlock(s); Unfortunately, you will break userspace ABI with this.