From owner-freebsd-current@freebsd.org Wed Sep 25 17:33:43 2019 Return-Path: Delivered-To: freebsd-current@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 1ABF412DFEC for ; Wed, 25 Sep 2019 17:33:43 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) 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 46dlXQ1SPlz4DHV for ; Wed, 25 Sep 2019 17:33:42 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: by mail-lj1-x242.google.com with SMTP id y3so6536880ljj.6 for ; Wed, 25 Sep 2019 10:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=bm1YNEzI3QTa1hwXjp+ylHpVjn+4yiaOMEveSiQOi5M=; b=rolKIsJwWD7xdNaBMaNBMUbMSD2iyCSEsA1CM5DqHjNGu9C8iU7jhA8W5rQrOm2N5Z Xm2CwQt74MFme+CvDkdJLF8yn/27CCwVBVb1y6M6HE8lZcGtsLBjWtnM66+AD1L2Xn2W GsyXBdcNflETX4pnWW/bzB6coJizrGzWgQb1hfXGq7jxaEhgbx2T+V0cpgh4pDMZyGhv i93ucLi5giUcM5YgiY38EHJSyhdnWqZpz+ezJqVY2Ic6De1ww8uHTyeAiSLxFbKOWhIm ebTEll6iZ67mmf9aEsI6g37MkTVTIUi5IF4p3WxcT1ZGjoDJxUKAk46krBMszlACReWL cKxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=bm1YNEzI3QTa1hwXjp+ylHpVjn+4yiaOMEveSiQOi5M=; b=XLgHqS7dziSOnHcb1v2O8GOzz44Z+V7sB7XYL7xgQx0s45y/BFepIQFQpC+MmWm6i9 PlEQtECrwcmaqwJqL05laAQUQxalrrp9nFKVXJ3GnUScEOVus/NlEVeNITyarZI7Eb0j yM2v6blZQ+Aj9rZm1xb96NIdKfAHJUVES99V9rnJGMrsdOVTtVTK4NqNX7cJ58BVY2v8 1G40FNzVR4QZ9HURjG2MAc2GAzr/9UppvSO12GLh7MHkUeQmgcp9g1HxbptI9i8t9VaT odLvRRIMh73qVStg6IfOR1nznYnA2V8co46kuurzyNTESUyo/ZBrQS+avOhrI0XY8T3l htOA== X-Gm-Message-State: APjAAAVYmLIsFRjUpGr5HhYcjzf9Nl3/3HQkIgD9oCTfWf41k7xoWNtm VpCB9QgJKz6G/Fo8hQqMu9g= X-Google-Smtp-Source: APXvYqx2wXhQ7IsyTSMWn1jvDbOQwrne2hBEGeBlWx0bLLCLOJc0jMuhZMZ416bGn+X5iON4pXi9Tw== X-Received: by 2002:a2e:3e09:: with SMTP id l9mr7421182lja.215.1569432820009; Wed, 25 Sep 2019 10:33:40 -0700 (PDT) Received: from MacBook-Air.local ([82.204.252.162]) by smtp.gmail.com with ESMTPSA id 196sm1327960ljj.76.2019.09.25.10.33.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Sep 2019 10:33:39 -0700 (PDT) Sender: Sergey Kandaurov Date: Wed, 25 Sep 2019 20:33:38 +0300 From: Sergey Kandaurov To: Ryan Stone Cc: FreeBSD Current Subject: Re: ktrace/kdump give incorrect message on unlinkat() failure due to capabilities Message-ID: <20190925173338.lvlg4cstdjcwwbtm@MacBook-Air.local> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 X-Rspamd-Queue-Id: 46dlXQ1SPlz4DHV X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=rolKIsJw; dmarc=none; spf=pass (mx1.freebsd.org: domain of pluknet@gmail.com designates 2a00:1450:4864:20::242 as permitted sender) smtp.mailfrom=pluknet@gmail.com X-Spamd-Result: default: False [-2.60 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-current@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[2.4.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.5.4.1.0.0.a.2.list.dnswl.org : 127.0.5.0]; IP_SCORE(-0.40)[ip: (3.15), ipnet: 2a00:1450::/32(-2.91), asn: 15169(-2.18), country: US(-0.05)]; FORGED_SENDER(0.30)[pluknet@freebsd.org,pluknet@gmail.com]; FREEMAIL_TO(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[pluknet@freebsd.org,pluknet@gmail.com]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Sep 2019 17:33:43 -0000 On Sat, Sep 21, 2019 at 08:43:58PM -0400, Ryan Stone wrote: > I have written a short test program that runs unlinkat(2) in > capability mode and fails due to not having the write capabilities: > > https://people.freebsd.org/~rstone/src/unlink.c > > If I run the binary under ktrace and look at the kdump output, it > gives the following incorrect output: > > 43775 unlink CALL unlinkat(0x3,0x7fffffffe995,0) > 43775 unlink NAMI "from.QAUlAA0" > 43775 unlink CAP operation requires CAP_LOOKUP, descriptor holds CAP_LOOKUP > 43775 unlink RET unlinkat -1 errno 93 Capabilities insufficient > > The message should instead say that the operation requires > CAP_UNLINKAT. Looking at sys/capsicum.h, I suspect that the problem > is related to the strange definition of CAP_UNLINKAT: > > #define CAP_UNLINKAT (CAP_LOOKUP | 0x0000000010000000ULL) FYI, with this grep it was able to decode capabilities. Index: lib/libsysdecode/mktables =================================================================== --- lib/libsysdecode/mktables (revision 352685) +++ lib/libsysdecode/mktables (working copy) @@ -157,7 +157,7 @@ gen_table "sigcode" "SI_[A-Z]+[[:space:]]+0(x[0-9abcdef]+)?" "sys/signal.h" gen_table "umtxcvwaitflags" "CVWAIT_[A-Z_]+[[:space:]]+0x[0-9]+" "sys/umtx.h" gen_table "umtxrwlockflags" "URWLOCK_PREFER_READER[[:space:]]+0x[0-9]+" "sys/umtx.h" -gen_table "caprights" "CAP_[A-Z_]+[[:space:]]+CAPRIGHT\([0-9],[[:space:]]+0x[0-9]{16}ULL\)" "sys/capsicum.h" +gen_table "caprights" "CAP_[A-Z_]+[[:space:]]+(CAPRIGHT|[()A-Z_|[:space:]]+CAP_LOOKUP)" "sys/capsicum.h" gen_table "sctpprpolicy" "SCTP_PR_SCTP_[A-Z_]+[[:space:]]+0x[0-9]+" "netinet/sctp_uio.h" "SCTP_PR_SCTP_ALL" gen_table "cmsgtypesocket" "SCM_[A-Z_]+[[:space:]]+0x[0-9]+" "sys/socket.h" if [ -e "${include_dir}/x86/sysarch.h" ]; then On unlink.c, it gives: 45494 unlink   CALL  cap_rights_limit(0x3,0x7fffffffead0)  45494 unlink   STRU  cap_rights_t CAP_LOOKUP  45494 unlink   RET   cap_rights_limit 0  45494 unlink   CALL  openat(AT_FDCWD,0x200323,0)  45494 unlink   NAMI  "/tmp"  45494 unlink   RET   openat 4  45494 unlink   CALL  cap_rights_limit(0x4,0x7fffffffead0)  45494 unlink   STRU  cap_rights_t CAP_LOOKUP,CAP_UNLINKAT  45494 unlink   RET   cap_rights_limit 0  45494 unlink   CALL  cap_enter  45494 unlink   RET   cap_enter 0  45494 unlink   CALL  unlinkat(0x3,0x7fffffffeaa5,0)  45494 unlink   NAMI  "from.YG6jQx2"  45494 unlink   CAP   operation requires CAP_LOOKUP,CAP_UNLINKAT, descriptor holds CAP_LOOKUP > I have observed the same problem with renameat(2) and > CAP_RENAMEAT_SOURCE and CAP_RENAMEAT_TARGET: > > https://people.freebsd.org/~rstone/src/rename.c 49410 rename   CAP   operation requires CAP_LOOKUP,CAP_RENAMEAT_SOURCE, descriptor holds CAP_LOOKUP