Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp324404rwd; Tue, 16 May 2023 01:20:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Qemuxm1HA35C/tlODEH5COWol7gcNF0oyowNVLbHxtIGBatFk25zDJmfZIX+n5f2t5oIS X-Received: by 2002:a17:902:9a43:b0:1ae:21a9:d081 with SMTP id x3-20020a1709029a4300b001ae21a9d081mr4942611plv.17.1684225229212; Tue, 16 May 2023 01:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684225229; cv=none; d=google.com; s=arc-20160816; b=DCGHywjcozpNHUjvaXTFZcf6oYtrHrh8UHqv2+XMpJdP0gHtJOAD897+1vWAIocEZ3 HtP1eEI0yavW8iabA+LFIrzHulRxcNTihk3R2f6Bvn6NFqlivlC3HAkI0on5lQ/3okeA RhQig6oD3dW1BGh+xeOF3wnenptc8TrHwob1ZzgG7yYkSQiILK+zjhZtc+a8+eu7ZAQ5 4qINIZMvdI2DbJcU/Y64pnakRHen7UD8e2nxLfgfv7RWZmhBEbWjNoe43z9BaFhMOO8s O09vTouh2x88GDdA8yIrtlxvK6ELg8dCmEeYTCs9Tykfsnxm/8fwGCxLpb+bAiLtIeuL k3qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=F5bRoS4xpTyVs5DFCkErH3y1wwSu6rDSU3Adh9JEHxc=; b=oFlUNRERHB9WkEFbfZ0s8AHJIApH+qZValmqW4zgqjA8X+FoBsTZ4HjKP0ttjJX4sT RDC9cHZ+60DfTzQa/HCPvY7yoPM767FkgzXbLyV9bM6WxFerwInu3/d3uNT80GMmGU8l 2Z88/fs5c/GJTAUBt/LRdSDhLNCOXUaLBjnbI0OeiCdM/mlClimagMqa+CBKS/3t29NF xyUM7efTweZMZWgez2reE3XZ54KEdahG+SEytDQRXsg6pgq64ioFhlzrUqYVFdKepVHg niOheAUzRkLyw+/rbXHJaqVIqNUdHf2HbdC0kUHtFIstWzn262lRGAiXzCPyjC4vm4tL gbxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=aWj+cMyK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx6-20020a17090af48600b00230a8355ff1si1179524pjb.181.2023.05.16.01.20.13; Tue, 16 May 2023 01:20:29 -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=@yandex-team.ru header.s=default header.b=aWj+cMyK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231515AbjEPIFS (ORCPT + 99 others); Tue, 16 May 2023 04:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbjEPIFR (ORCPT ); Tue, 16 May 2023 04:05:17 -0400 Received: from forwardcorp1b.mail.yandex.net (forwardcorp1b.mail.yandex.net [178.154.239.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 391C844B0; Tue, 16 May 2023 01:05:14 -0700 (PDT) Received: from mail-nwsmtp-smtp-corp-main-11.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-11.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2c24:0:640:73f8:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 2A0B360AC5; Tue, 16 May 2023 11:05:12 +0300 (MSK) Received: from [IPV6:2a02:6b8:8f:4:7a31:c1ff:fef2:bf07] (unknown [2a02:6b8:8f:4:7a31:c1ff:fef2:bf07]) by mail-nwsmtp-smtp-corp-main-11.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id A5WFgX1OmGk0-7LFYAc0J; Tue, 16 May 2023 11:05:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1684224311; bh=F5bRoS4xpTyVs5DFCkErH3y1wwSu6rDSU3Adh9JEHxc=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=aWj+cMyK7wLaA426sbgLxmJI/jn353ehUh0W4FX9Qt5m3TfTpQAarrBB3ryPNv0qX xjFvuwwj5GHQF2ERpKOU8lfeIiSyMIJVG8+C8CXYxng6XyjTtQsAApcicaGG3f0t/W SJlqOaXQwOF8rzWBTP+JXWoMGxbQvkNW+wHgOJqc= Authentication-Results: mail-nwsmtp-smtp-corp-main-11.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru Message-ID: Date: Tue, 16 May 2023 11:05:10 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH] fs/coredump: open coredump file in O_WRONLY instead of O_RDWR To: Linus Torvalds , Christian Brauner Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, ptikhomirov@virtuozzo.com, Andrey Ryabinin References: <20230420120409.602576-1-vsementsov@yandex-team.ru> <14af0872-a7c2-0aab-b21d-189af055f528@yandex-team.ru> <20230515-bekochen-ertrinken-ce677c8d9e6e@brauner> Content-Language: en-US From: Vladimir Sementsov-Ogievskiy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 15.05.23 22:13, Linus Torvalds wrote: > On Mon, May 15, 2023 at 11:50 AM Linus Torvalds > wrote: >> >> It's strange, because the "O_WRONLY" -> "2" change that changes to a >> magic raw number is right next to changing "(unsigned short) 0x10" to >> "KERNEL_DS", so we're getting *rid* of a magic raw number there. > > Oh, no, never mind. I see what is going on. > > Back then, "open_namei()" didn't actually take O_RDWR style flags AT ALL. > > The O_RDONLY flags are broken, because you cannot say "open with no > permissions", which we used internally. You have > > 0 - read-only > 1 - write-only > 2 - read-write > > but the internal code actually wants to match that up with the > read-write permission bits (FMODE_READ etc). > > And then we've long had a special value for "open for special > accesses" (format etc), which (naturally) was 3. > > So then the open code would do > > f->f_flags = flag = flags; > f->f_mode = (flag+1) & O_ACCMODE; > if (f->f_mode) > flag++; > > which means that "f_mode" now becomes that FMODE_READ | FMODE_WRITE > mask, and "flag" ends up being a translation from that O_RDWR space > (0/1/2/3) into the FMODE_READ/WRITE space (1/2/3/3, where "special" > required read-write permissions, and 0 was only used for symlinks). > > We still have that, although the code looks different. > > So back then, "open_namei()" took that FMODE_READ/WRITE flag as an > argument, and the "O_WRONLY" -> "2" change is actually a bugfix and > makes sense. The O_WRONLY thing was wrong, because it was 1, which > actuall ymeant FMODE_READ. > > And back then, we didn't *have* FMODE_READ and FMODE_WRITE. > > So just writing it as "2" made sense, even if it was horrible. We > added FMODE_WRITE later, but never fixed up those core file writers. > > So that 0.99pl10 commit from 1993 is actually correct, and the bug > happened *later*. > > I think the real bug may have been in 2.2.4pre4 (February 16, 1999), > when this happened: > > - dentry = open_namei(corefile,O_CREAT | 2 | O_TRUNC | O_NOFOLLOW, 0600); > ... > + file = filp_open(corefile,O_CREAT | 2 | O_TRUNC | O_NOFOLLOW, 0600); > > without realizing that the "2" in open_namei() should have become a > O_WRONLY for filp_open(). > > So I think this explains it all. > > Very understandable mistake after all. > > Linus Wow that's became a detective story, great thanks! [took note to check history myself next time] -- Best regards, Vladimir