Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1953495pxb; Mon, 23 Aug 2021 08:28:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3xrrYpnoV8iAGmKN1ItYBzXSSZsmhDXol3L3h6XN8mxiqidgKiVnkDW/90cJxWapURlOX X-Received: by 2002:a17:907:7704:: with SMTP id kw4mr35470040ejc.23.1629732510162; Mon, 23 Aug 2021 08:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629732510; cv=none; d=google.com; s=arc-20160816; b=z27clR0Phed16O8dsTZrNTsZKriI6EpzJjB4w3fyP8RDtBlDVIejAteP7fT0QgpaZQ 2TVyeujQqAq8BPXZpHNrFJFPb4Kw8hdC29LZjHAj0+jucxPq/NECoMqzFVR9l7KrB7US ravj7OeqpDRCD5JjtyNvkrK0gei+gRVlOUPgVUCcUSs04IdTJyFG9CgqRUoneM/0Wj13 SUchkmivD3xKBKRw6iRJJmLh+e5rzYq92wxgeLH+Iz4bYsKtexvBOa0jkG69CksEBNjT 5o/0YyLMRUUPBCzpq4fUsqEiPMRuh3J8w/w7VhwvLRHMj28vbW53x86ljAXe4ZI7kQHk 0bgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=pXBRA/KC8RXOCFqRJFNMsI12Ya9Yxd1nh3nJBCGyvh0=; b=h/zJXwVruP+lfQomlW6p3DWcwRubwLUdyMpphNw2W6rDn+yXrKx0LwaqjTtTQkyOZG 1thf+UpvTdBWYuhxH4MJZzEsLhxwvo7KndKu6LVTgwY/LsNruaaBZjJE8ke9m2+tdcBv 7lebfGzEfMB8zjjTLgOK0IOm9rNjbMAjtRVAWamiZOiTbMAQcjxq1Pf64NUsguI9krEx C1SYfV//VJlH1TVYp3hxBSoQCIj40PHthQ6YQpcgBCArw9mbCQryZk8rMNowipD4Wq+J Yh8J8hITIHI1LDfwJkN76Z/ohIypSYwOLWN28dCYCMF5Pnk8zKprYDHQhAP1peLTw87q KCaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si5876925edd.151.2021.08.23.08.28.07; Mon, 23 Aug 2021 08:28:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbhHWPZX (ORCPT + 99 others); Mon, 23 Aug 2021 11:25:23 -0400 Received: from mga06.intel.com ([134.134.136.31]:31009 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbhHWPZW (ORCPT ); Mon, 23 Aug 2021 11:25:22 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10085"; a="278136554" X-IronPort-AV: E=Sophos;i="5.84,344,1620716400"; d="scan'208";a="278136554" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2021 08:24:39 -0700 X-IronPort-AV: E=Sophos;i="5.84,344,1620716400"; d="scan'208";a="526100722" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2021 08:24:38 -0700 Date: Mon, 23 Aug 2021 08:24:37 -0700 From: "Luck, Tony" To: Borislav Petkov Cc: Jue Wang , Ding Hui , naoya.horiguchi@nec.com, osalvador@suse.de, Youquan Song , huangcun@sangfor.com.cn, x86@kernel.org, linux-edac@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] x86/mce: Avoid infinite loop for copy from user recovery Message-ID: <20210823152437.GA1637466@agluck-desk2.amr.corp.intel.com> References: <20210706190620.1290391-1-tony.luck@intel.com> <20210818002942.1607544-1-tony.luck@intel.com> <20210818002942.1607544-2-tony.luck@intel.com> <20210820185945.GA1623421@agluck-desk2.amr.corp.intel.com> <20210820203356.GA1623896@agluck-desk2.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 22, 2021 at 04:46:14PM +0200, Borislav Petkov wrote: > On Fri, Aug 20, 2021 at 01:33:56PM -0700, Luck, Tony wrote: > > The new version (thanks to All fixing iov_iter.c) now does > > exactly what POSIX says should happen. If I have a buffer > > with poison at offset 213, and I do this: > > > > ret = write(fd, buf, 512); > > > > Then the return from write is 213, and the first 213 bytes > > from the buffer appear in the file, and the file size is > > incremented by 213 (assuming the write started with the lseek > > offset at the original size of the file). > > ... and the user still gets a SIGBUS so that it gets a chance to handle > the encountered poison? I.e., not retry the write for the remaining 512 > - 213 bytes? Whether the user gets a SIGBUS depends on what they do next. In a typical user loop trying to do a write: while (nbytes) { ret = write(fd, buf, nbytes); if (ret == -1) return ret; buf += ret; nbytes -= ret; } The next iteration after the short write caused by the machine check will return ret == -1, errno = EFAULT. Andy Lutomirski convinced me that the kernel should not send a SIGBUS to an application when the kernel accesses the poison in user memory. If the user tries to access the page with the poison directly they'll get a SIGBUS (page was unmapped so user gets a #PF, but the x86 fault handler sees that the page was unmapped because of poison, so sends a SIGBUS). > If so, do we document that somewhere so that application writers can > know what they should do in such cases? Applications see a failed write ... they should do whatever they would normally do for a failed write. -Tony