From patchwork Mon Nov 14 22:20:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wilder X-Patchwork-Id: 694748 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tHlHw2BBsz9t2b for ; Tue, 15 Nov 2016 09:17:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939002AbcKNWRN (ORCPT ); Mon, 14 Nov 2016 17:17:13 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60446 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933656AbcKNWRK (ORCPT ); Mon, 14 Nov 2016 17:17:10 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAEMDgHM083648 for ; Mon, 14 Nov 2016 17:17:10 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 26qkfp65jn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 14 Nov 2016 17:17:10 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Nov 2016 15:17:09 -0700 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 14 Nov 2016 15:17:06 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id EAFF83E4003F; Mon, 14 Nov 2016 15:17:05 -0700 (MST) Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAEMH5tI13762976; Mon, 14 Nov 2016 15:17:05 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6B02C604C; Mon, 14 Nov 2016 15:17:05 -0700 (MST) Received: from ltc.linux.ibm.com (unknown [9.16.170.189]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 8EB6EC603C; Mon, 14 Nov 2016 15:17:05 -0700 (MST) MIME-Version: 1.0 Date: Mon, 14 Nov 2016 14:20:19 -0800 From: dwilder To: mtk.manpages@gmail.com Cc: linux-man@vger.kernel.org, netdev@vger.kernel.org Subject: [patch] netlink.7: srcfix Change buffer size in example code about reading netlink message. X-Sender: dwilder@us.ibm.com User-Agent: Roundcube Webmail/1.0.1 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111422-8235-0000-0000-0000099D3C27 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006078; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00780706; UDB=6.00376500; IPR=6.00558209; BA=6.00004879; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013326; XFM=3.00000011; UTC=2016-11-14 22:17:08 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111422-8236-0000-0000-00003676F841 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-14_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611140423 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The example code in netlink(7) (for reading netlink message) suggests using a 4k read buffer with recvmsg. This can cause truncated messages on systems using a page size is >4096. Please see: linux/include/linux/netlink.h (in the kernel source) /* * skb should fit one page. This choice is good for headerless malloc. * But we should limit to 8K so that userspace does not have to * use enormous buffer sizes on recvmsg() calls just to avoid * MSG_TRUNC when PAGE_SIZE is very large. */ #if PAGE_SIZE < 8192UL #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE) #else #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL) #endif #define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN) I was troubleshooting some up-stream code on a ppc64le system (page:size of 64k) This code had duplicated the example from netlink(7) and was using a 4k buffer. On x86-64 with a 4k page size this is not a problem, however on the 64k page system some messages were truncated. Using an 8k buffer as implied in netlink.h prevents problems with any page size. Lets change the example so others don't propagate the problem further. Signed-off-by David Wilder --- man7/netlink.7.orig 2016-11-14 13:30:36.522101156 -0800 +++ man7/netlink.7 2016-11-14 13:30:51.002086354 -0800 @@ -511,7 +511,7 @@ .in +4n .nf int len; -char buf[4096]; +char buf[8192]; struct iovec iov = { buf, sizeof(buf) }; struct sockaddr_nl sa; struct msghdr msg;