From owner-freebsd-hackers@freebsd.org Thu Apr 22 04:54:56 2021 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 414135FF751 for ; Thu, 22 Apr 2021 04:54:56 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FQlTW1S6hz4sbC for ; Thu, 22 Apr 2021 04:54:54 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: by mail-lf1-f49.google.com with SMTP id r128so43135086lff.4 for ; Wed, 21 Apr 2021 21:54:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=L4BB+AxEVlv78S9srfCr+F5/EHAGUXkMBf6cJwczNK4=; b=pB11+ZjRvKv+7LNLbkG/ftuTnBvW5aggZSiRm5FRIu7jXzD/BMbJrh5sEkCErzZwTP Tsq593U1CUR2nes72v82zFeqgAQarGF3s+lCzNuyt3t7a/LIHAkroNcprudqE38/oaiK YgeWb6KhgraaLZ40PPPOpfcIylI15cBzuza9WIGC9u90hTvwotkkw/oo4Q8X+lv2eNFD coWrn1HzCdbjVCXh3YOTNx8425IJzQVbB/rbrv08bWysyK+i/pdqpyOg7609CneqkRlI Jni9ZQzc7H9dWl0l3Ke5TuajBkBIeqwwQg6In6UsJTU1UX3dd21bMwVCIAhh5eyelbDM jBTg== X-Gm-Message-State: AOAM531wMztPCZGH12KjrTWx1rbqXVQ0D9x6Vcj0NEbp1xpDur5aE2ng /AIAulOxDtTcHricoe3kqTe92HlhblMD+g== X-Google-Smtp-Source: ABdhPJw9jAUPDOsDqw0HXYiSnhGpfEytV+n7pqxeROXlIiQeT96bgBeWWGIjLnoVeHkJPFIy9fgDyw== X-Received: by 2002:a19:ca0d:: with SMTP id a13mr1139716lfg.253.1619067292964; Wed, 21 Apr 2021 21:54:52 -0700 (PDT) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com. [209.85.208.179]) by smtp.gmail.com with ESMTPSA id y5sm147294lfg.154.2021.04.21.21.54.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Apr 2021 21:54:52 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id u20so50312459lja.13 for ; Wed, 21 Apr 2021 21:54:52 -0700 (PDT) X-Received: by 2002:a05:651c:205:: with SMTP id y5mr1133283ljn.301.1619067292420; Wed, 21 Apr 2021 21:54:52 -0700 (PDT) MIME-Version: 1.0 References: <40116716-D8D9-438D-A168-B26A112D199E@yahoo.com> In-Reply-To: <40116716-D8D9-438D-A168-B26A112D199E@yahoo.com> From: Gleb Popov Date: Thu, 22 Apr 2021 07:54:26 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: A bug with getsockopt(SOL_LOCAL, LOCAL_PEERCRED) ? To: Mark Millard Cc: freebsd-hackers X-Rspamd-Queue-Id: 4FQlTW1S6hz4sbC X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of 6yearold@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=6yearold@gmail.com X-Spamd-Result: default: False [0.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; RCVD_COUNT_THREE(0.00)[4]; TO_DN_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_TO(0.00)[yahoo.com]; FORGED_SENDER(0.30)[arrowd@freebsd.org,6yearold@gmail.com]; SUBJECT_ENDS_QUESTION(1.00)[]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FROM_NEQ_ENVFROM(0.00)[arrowd@freebsd.org,6yearold@gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; ARC_NA(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[209.85.167.49:from]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(1.00)[1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; SPAMHAUS_ZRD(0.00)[209.85.167.49:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.167.49:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.167.49:from]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Technical discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2021 04:54:56 -0000 On Thu, Apr 22, 2021 at 1:00 AM Mark Millard wrote: > > On 2021-Apr-21, at 11:27, Gleb Popov wrote: > > > > This makes sense, thanks. > > > > However, this code works on Linux and seems to return credentials of the > user that started the process. I actually stumbled upon this when porting > this code: > https://github.com/CollaboraOnline/online/blob/master/net/Socket.cpp#L805 > > > > Would it make sense if FreeBSD followed Linux semantics in this case? If > not, what are my options for porting the software? > > From what I can tell . . . > > FreeBSD defines LOCAL_PEERCRED and what goes with its use, not linux. > Linux defines SO_PEERCRED and what goes with its use, not FreeBSD. > > If I understand right, your code is incompatible with the referenced > CollaboraOnline code from just after the #else (so __FreeBSD__ case, > not the linux case): > > getsockopt(getFD(), 0, LOCAL_PEERCRED, &creds, &credSize) > vs. your: > getsockopt(s, SOL_LOCAL, LOCAL_PEERCRED, &creds, &credSize) > > Note the 0 vs. the SOL_LOCAL. Your code is a mix of Linux > and FreeBSD code when it should not be. > SOL_LOCAL is defined to 0, so this is fine. > See also the following that involved replacing a SOL_LOCAL > with a 0 for getsockopt used with LOCAL_PEERCRED: > > https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234722 > > Yes, I'm aware that Linux SO_PEERCRED operates on socket level, while ours operates on level 0. This is taken in account in the code I posted. As I said, the error stems from the fact that Linux allows getting creds from the listening socket.