Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1012186imm; Mon, 9 Jul 2018 15:16:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdeW4KuHk+K2cO04qOGJUsMoayMCPaLv+khfxdnd8k9jZy5T3mDkcdyxL8MuThmnDpNaPZW X-Received: by 2002:a65:62cd:: with SMTP id m13-v6mr20253353pgv.280.1531174619518; Mon, 09 Jul 2018 15:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531174619; cv=none; d=google.com; s=arc-20160816; b=pSWA4YqIq0HhNE3XEQ8uCO/6LD3N1iDjlMdtROWwOsBPsQvBujcnvv5HzRblaYNUiw 3gPGGat7wIGIb7zfs8i7+dkoAOLgq+u6Y4/suTJJVY+ihy8GFqGbnfD+BLiFvmuGh6I5 sQaBzBwH6UdnwilgzAVMO5lRqcXoLC1a0G9CsL62ZhxbelZ+g5TYd5AIObzQsmLYCxhd XFAxgf6PRsIELRu1gbf4VL3ENpUFcGXM9bmwGd9RLibW9wYGrDD2IB4wG5IpAVF5rfwB BXnn3QRG9HdLePDsSwR95cRT+ZoBp57AXpbeAF8tMTrLfTRDMoC8xpCjD6lGNFBNc4S5 570Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=X3gSx+iTRmC/ZpwiUkRnuh65hOij+TbE/z06RE5jJU8=; b=dpLNM/me2xzvwkdcq+sBHyVRh5MQiLBZSP08j3NZojXMImd2GDaiFBNMTHf+WwOGo8 c3voeh/S2YRbSlwpCM+pXmFKFn6ovQb/WWUBQnjLkn8WWb5Cacm5EIX7Ad4tvi8B2pOt voEUQUmRTvJ78OxtR4sp3w2kyZ4vZVKfeKXEf5VncfYt1FK4PFEth342Z/7e1IctAt1F mQC9G5Kl9VQu/WYDza2dY6OwHSeViuqrr5HbDXu45qQpWNquwHB3BollUtHHdzXRZ3pO 1jsoFPLLWi+BnWTK+J8B1MGwWy5WUhQnSF8QPX5nzQy4PQXWXoxjTOvB1SikGKSHF01S M6wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=o1bLLpxI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13-v6si14054329pgv.374.2018.07.09.15.16.44; Mon, 09 Jul 2018 15:16:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=o1bLLpxI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754544AbeGIWO2 (ORCPT + 99 others); Mon, 9 Jul 2018 18:14:28 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44658 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932620AbeGIWOZ (ORCPT ); Mon, 9 Jul 2018 18:14:25 -0400 Received: by mail-wr1-f66.google.com with SMTP id r16-v6so12523762wrt.11; Mon, 09 Jul 2018 15:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=X3gSx+iTRmC/ZpwiUkRnuh65hOij+TbE/z06RE5jJU8=; b=o1bLLpxIy0Q+p4MHtlcNH0MKDU6jl0hjt4OTSAwQv5fVH4FJLnudLKOBaWPgYxVHro gWtUxxpzSkbcjSkSfRqnjvZdHu3OCfAekUWSzxB8Q7jIWs0XJ5h/IgO/kp/b5xxU1y+H Yz6b8vtwTE7Hd4mkFiM59a01mc+ehr2yKIH1f6IAMJNlczIPiFPjI6Ewq0mLyY3Cbrat TrV6m3Kku0CdMIVWS8comQ+g9mBTqb4pJqSOPV0w2v70u6sW622OSf+9hcHKVO+82xsg dKHIU5Pt1mU0+ax7j1GZw5/1RaHY2Ni4ndR62yB8S0b5spruxuj58yLYK1RMMX/S+wyR uX7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=X3gSx+iTRmC/ZpwiUkRnuh65hOij+TbE/z06RE5jJU8=; b=FwlzyhBH6AA7qiYHWxUvlHX6W0aBjnsLEY0vw4B5tA/WgZmtxTrvjNMgW3OkokuS8N o46rk9JD19ir1t7vQ0fqu909Q20ue2cQIorI5nopEnR9cBRz/ytJzDNb6sXEbP+WZeTt AnK9eUOOZ7ZsSu0ZxBHLF4R2hIMKANSTmkNruX5gglzCIz0Y1uj61PA9wkdvYJFqwFDq /hAdeSnFjFC1Mmb4X2W5zHnVR/MQjjtqXTL8JDKvCsLg9K1MxLQ49unecgYJ3QjcnBYW O0MGktV3mgoOlMMj13MkHPrbfEktN+1+/VDrOc0qRKVV/Qx1vgT6XGaxysdm9Gle+Dtx 200Q== X-Gm-Message-State: APt69E2d7AGxbpMNiUB7okOppdu5W8kNoCSeD/Xc/WEHUOLuqctj96fk +xwFm3c9KSnKP3YqX2+4dNU= X-Received: by 2002:adf:d08c:: with SMTP id y12-v6mr16545445wrh.152.1531174464436; Mon, 09 Jul 2018 15:14:24 -0700 (PDT) Received: from [192.168.8.10] ([185.175.214.210]) by smtp.gmail.com with ESMTPSA id s17-v6sm12260230wmc.34.2018.07.09.15.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 15:14:23 -0700 (PDT) Subject: Re: [V9fs-developer] [PATCH] Integer underflow in pdu_read() To: Al Viro Cc: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net, davem@davemloft.net, v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com References: <20180709192651.28095-1-tomasbortoli@gmail.com> <20180709193151.GI30522@ZenIV.linux.org.uk> From: Tomas Bortoli Openpgp: preference=signencrypt Autocrypt: addr=tomasbortoli@gmail.com; prefer-encrypt=mutual; keydata= xsFNBFpCTZMBEADNZ1+Ibh0Z4pgGRcd1aOUMbe/YfHktmajjcoTnKmZZunjoUVAl8waeLITd BC2c8i1wHzHcnthrmb1izs5XlG6PZnl8n5tjysSNbwggzS1NcEK1qgn5VjNlHQ5aRMUwCC51 kicBiNmlQk2UuzzWwdheRGnaf+O1MNhC0GBeEDKQAL5obOU92pzflv6wWNACr+lHxdnpyies mOnRMjH16NjuTkrGbEmJe+MKp0qbjvR3R/dmFC1wczniRMQmV5w3MZ/N9wRappE+Atc1fOM+ wP7AWNuPvrKg4bN5uqKZLDFH7OFpxvjgVdWM40n0cQfqElWY9as+228Sltdd1XyHtUWRF2VW O1l5L0kX0+7+B5k/fpLhXqD3Z7DK7wRXpXmY59pofk7aFdcN97ZK+r6R7mqrwX4W9IpsPhkT kUyg3/Dx/khBZlJKFoUP325/hoH684bSiPEBroel9alB7gTq2ueoFwy6R3q5CMUw3D+CZWHA 3xllu46TRQ/Vt2g0cIHQNPoye2OWYFJ6kSEvaLpymjNDJ9ph2EuHegonDfOaYSq34ic2BcdB JkCgXRLP5K7KtRN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li/I/zegeblInnLi08Gq6mT6RkD6wV9HE5U3 EIU0rDPyJo54MW39wGjfC2+PM5I0xebbxtnuTewRchVVfm7UWgLAy11pV3xM4wMSJOuqVMOz jYpWKYxDTpvsZ0ginUUY993Gb8k/CxjABEMUGVHhQPZ0OzjHIKS6cTzN6ue8bB+CGOLCaQp1 C0NRT5Tn9zpLxtf5nBExFd/zVENY5vAV2ZbKQdemO54O7j6B9DSgVRrm83GCZxbL4d+qTYBF 3tSCWw/6SG1F3q9gR9QrSC2YRjCmhijUVEh6FhZwB58TNZ1sEEttrps8TDa5tUd9 Message-ID: Date: Tue, 10 Jul 2018 00:14:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180709193151.GI30522@ZenIV.linux.org.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/09/2018 09:31 PM, Al Viro wrote: > On Mon, Jul 09, 2018 at 09:26:51PM +0200, Tomas Bortoli wrote: >> The pdu_read() function suffers from an integer underflow. >> When pdu->offset is greater than pdu->size, the length calculation wil= l have >> a wrong result, resulting in an out-of-bound read. >> This patch modifies also pdu_write() in the same way to prevent the sa= me >> issue from happening there and for consistency. > What does cause the calls of pdu_read() in such conditions and shouldn'= t *that* > be dealt with? Mmh I think that's caused by p9_parse_header(). That function reads the first 7 bytes of a PDU regardless of the current offset. It then sets the PDU length to the one read and then it restores the original offset. Therefore, it's possible to set a size < offset here. (to be 100% sure I'd need more debugging) We can prevent it in p9_parse_header(), but if the invariant offset < size gets broken elsewhere we fall back to the underflow. Enforcing it in pdu_read() should be the safest thing to do as it would detect *any* bad read.