From patchwork Sun Aug 18 08:31:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 11099459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69B031395 for ; Sun, 18 Aug 2019 08:32:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5794E28814 for ; Sun, 18 Aug 2019 08:32:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4773928885; Sun, 18 Aug 2019 08:32:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A462E28814 for ; Sun, 18 Aug 2019 08:32:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzGaj-0000Gb-Mb; Sun, 18 Aug 2019 08:31:09 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzGai-0000GW-Bp for xen-devel@lists.xenproject.org; Sun, 18 Aug 2019 08:31:08 +0000 X-Inumbo-ID: 84011b5c-c192-11e9-8be1-12813bfff9fa Received: from userp2120.oracle.com (unknown [156.151.31.85]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 84011b5c-c192-11e9-8be1-12813bfff9fa; Sun, 18 Aug 2019 08:31:04 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7I8UAkQ045583; Sun, 18 Aug 2019 08:31:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=OscEuJNSgaecc7omNE4pQTG5ugKKHTX9RKDQmcCtGr8=; b=VmfD0lZbcw1KI7nt0/A4dxSbgisrKmDi0ksS4DOvJSPFmZguw8QqN2r6SDm0Z6wBNXmX G9BAwNYAcfAOXkDya1jgpQlSWYNjdB+cjqm5KpmO9/O5DiYiytDKpaY/fxumu/OnzHuy bqVLfnlthkywEusuaLChoXe8DikNC9QC5x70lHKijTiX8EYQ58fAgNB/Sehg3d3xadve cIvZ77/epLNw47iZhE+9dRhe/nInKAarpbCUqO2bxH8hlMTOBZF9b3hDtUoKNAdhHiBj ZX0/GJSPhIZwysvofZ/ZXsZfA25bQwi/C6L147375Qu19zddOcs0YzKkSOVJ99Yzhu/L 1A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2uea7qawt2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 18 Aug 2019 08:31:02 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7I8S93Q053923; Sun, 18 Aug 2019 08:31:02 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2ue8wx3qu9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 18 Aug 2019 08:31:02 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x7I8V1h2012172; Sun, 18 Aug 2019 08:31:01 GMT MIME-Version: 1.0 Message-ID: Date: Sun, 18 Aug 2019 01:31:00 -0700 (PDT) From: Dongli Zhang To: X-Mailer: Zimbra on Oracle Beehive Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9352 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908180094 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9352 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908180094 Subject: [Xen-devel] Question on xen-netfront code to fix a potential ring buffer corruption X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: jgross@suse.com, netdev@vger.kernel.org, Joe Jin Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hi, Would you please help confirm why the condition at line 908 is ">="? In my opinion, we would only hit "skb_shinfo(skb)->nr_frag == MAX_SKB_FRAGS" at line 908. 890 static RING_IDX xennet_fill_frags(struct netfront_queue *queue, 891 struct sk_buff *skb, 892 struct sk_buff_head *list) 893 { 894 RING_IDX cons = queue->rx.rsp_cons; 895 struct sk_buff *nskb; 896 897 while ((nskb = __skb_dequeue(list))) { 898 struct xen_netif_rx_response *rx = 899 RING_GET_RESPONSE(&queue->rx, ++cons); 900 skb_frag_t *nfrag = &skb_shinfo(nskb)->frags[0]; 901 902 if (skb_shinfo(skb)->nr_frags == MAX_SKB_FRAGS) { 903 unsigned int pull_to = NETFRONT_SKB_CB(skb)->pull_to; 904 905 BUG_ON(pull_to < skb_headlen(skb)); 906 __pskb_pull_tail(skb, pull_to - skb_headlen(skb)); 907 } 908 if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { 909 queue->rx.rsp_cons = ++cons; 910 kfree_skb(nskb); 911 return ~0U; 912 } 913 914 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, 915 skb_frag_page(nfrag), 916 rx->offset, rx->status, PAGE_SIZE); 917 918 skb_shinfo(nskb)->nr_frags = 0; 919 kfree_skb(nskb); 920 } 921 922 return cons; 923 } The reason that I ask about this is because I am considering below patch to avoid a potential xen-netfront ring buffer corruption. If there is skb left in list when we return ~0U, queue->rx.rsp_cons may be set incorrectly. While I am trying to make up a case that would hit the corruption, I could not explain why (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)), but not just "==". Perhaps __pskb_pull_tail() may fail although pull_to is less than skb_headlen(skb). Thank you very much! Dongli Zhang diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 8d33970..48a2162 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -906,7 +906,7 @@ static RING_IDX xennet_fill_frags(struct netfront_queue *queue, __pskb_pull_tail(skb, pull_to - skb_headlen(skb)); } if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { - queue->rx.rsp_cons = ++cons; + queue->rx.rsp_cons = cons + skb_queue_len(list) + 1; kfree_skb(nskb); return ~0U; }