From owner-freebsd-net@freebsd.org Wed Dec 27 22:10:42 2017 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 35CB7E80ECC for ; Wed, 27 Dec 2017 22:10:42 +0000 (UTC) (envelope-from nparhar@gmail.com) Received: from mail-pl0-x233.google.com (mail-pl0-x233.google.com [IPv6:2607:f8b0:400e:c01::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F2DF07A8DD for ; Wed, 27 Dec 2017 22:10:41 +0000 (UTC) (envelope-from nparhar@gmail.com) Received: by mail-pl0-x233.google.com with SMTP id 62so18634578pld.7 for ; Wed, 27 Dec 2017 14:10:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=vPr1Hj/jUBjvqGSwSPBtz/j3GseTuRWDPVMZ8Z9MNQk=; b=QKHEe67V4iVJO0CEowI/XHvdk5pjfD6kiuNjFD6kgpsioxFlb8jpCVk8kRwXcVJxB0 7f4k0tPrTQUPJwYj3bGrOsSMjvdVHx14vCeMx5AxrhoHav7zPswMc7Iz80gn6W5JAqqT XbZfroTyPTiSGx0543lO9uGx+G46+aRnMeIIxZizvq2fcHIp3Fiw6r/kLLA6Bend6EeO Vic9EpHaqlnONzbfRcEyq6XnMnUPsEhuZT0iGgHOpODsNzhoUhIQ66I2AYSO5+JQHY27 ch5OPBL/XGay1wga+mfXAIdX8nW5IxFN2UcVxVuDQTqaJS9miwCz45dI/j86ewE0uUAn +IwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=vPr1Hj/jUBjvqGSwSPBtz/j3GseTuRWDPVMZ8Z9MNQk=; b=HwPhcDYlS90ouENfBxmtVttLn0durYH29smWdJkrFcRifbKd8WjbLeOJP5SxZPOQcy UhS44ZUdNLj1fT079XTW7kQ5QzQW5h3FzikEo5Me81OmSEEj/ADKgJXS5rn6drNZbv9C Y+qUKKVRKgYdWvdAi5ZOp1FBoYdQRXhVwo3TOcUy+clTl3A2VAILg2ET9aSz19ittl/D GZljNRUuOcEkf1dKeNiBuzXui8kQaBqpsW2MKdykiDqzFQTVAahig5QCnNEAZatn+2Yf aKIrUTddUBFcxapM8uICjExFp70ftIiNuocGHXg9wWuxwASB99VHqYeEg7EKVjexcxCI U1RA== X-Gm-Message-State: AKGB3mImBvLlqnRyBGE5W2wADpmJ9WfF7JfO1Bzhx52ZoLQuycxDyOiS FqUnlpX1DxIGleTXDf9a9nR1hQ== X-Google-Smtp-Source: ACJfBosYhp7iRWUU2uPqmk+6zifoTM9NXjdilmMW8LoRscjBygyr52EaMb9XhLUGIRHrp85o+DtJHg== X-Received: by 10.84.244.199 with SMTP id f7mr29814498plt.181.1514412641101; Wed, 27 Dec 2017 14:10:41 -0800 (PST) Received: from [10.192.166.0] (stargate.chelsio.com. [12.32.117.8]) by smtp.googlemail.com with ESMTPSA id n6sm73232513pfg.188.2017.12.27.14.10.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2017 14:10:40 -0800 (PST) Sender: Navdeep Parhar Subject: Re: [freebsd-current]Who should reset M_PKTHDR flag in m_buf when IP packets are fragmented. m_unshare panic throw when IPSec is enabled To: "Andrey V. Elsukov" , Harsh Jain , freebsd-net@freebsd.org References: <73302ead-b2e9-c25b-4d11-475f38dec1a1@chelsio.com> <993c58bb-3bf2-d6a3-9a05-13e1631aec87@yandex.ru> From: Navdeep Parhar Message-ID: <2887a9d7-6b72-25a4-84da-74578b54d103@FreeBSD.org> Date: Wed, 27 Dec 2017 14:10:39 -0800 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Dec 2017 22:10:42 -0000 On 12/27/2017 12:59, Andrey V. Elsukov wrote: > On 27.12.2017 23:09, Navdeep Parhar wrote: >>> It is not clear to me why it helps. The panic happens on outbound path, >>> where mbuf should be allocated by network stack and should be writeable. >>> ip_reass() usually used on inbound path. I think the patch just hides >>> the problem in another place. >>> Do you mean that cxgbe can produce !WRITEABLE mbuf for received packet >>> and then pass it to the network stack? >> >> Yes, cxgbe does that. But I think the real bug here is in ip_reass >> because it doesn't properly get rid of the pkthdr of the fragments while >> creating the reassembled datagram. cxgbe happens to trip on this easily >> because it often creates !WRITEABLE mbufs. > > From the quick look, I don't see the code in netipsec and in crypto, > that does check mbuf is WRITEABLE. It is expected that in most cases for > received mbuf the data will be decrypted and copied back into the given > buffer. Can this lead to memory corruption? > >> This should fix it: >> https://people.freebsd.org/~np/ip_reass_demotehdr.diff >> >> It will also fix leaks in configurations where mbuf tags are in use by >> default (for example with MAC), ip_reass is involved during rx, and the >> mbuf chain never gets m_demote'd elsewhere (meaning ip_reass should have >> freed the tags itself). > > I think such chain with several mbufs with M_PKTHDR flag is created with > m_cat() due to !WRITEABLE mbufs. And when mbuf chain will be freed, the > tags chain will be also destroyed by mbuf zone destructor. I see m_freem/m_free will do the right thing but such a chain isn't legal. m_unshare is complaining about it here. m_sanity on the chain will fail too. m_cat says it will leave the pkthdr alone so it is working as advertised. It's the caller's job to clean up headers etc. to keep the mbuf chain valid. > > If you think it solves the problem, the IPv6 fragment reassembly > probably needs the same code. But I think that M_WRITEABLE flag is not > properly handled is the problem too. > I think M_WRITEABLE is being handled properly here. m_unshare deals with the chain just fine apart from this assert about multiple M_PKTHDR. I'll fix IP6 reassembly too and post to phabricator if the change looks ok? Regards, Navdeep