Module Name: src Committed By: rtr Date: Thu May 21 02:04:22 UTC 2015
Modified Files: src/sys/kern: subr_tftproot.c src/sys/nfs: krpc_subr.c nfs_boot.c nfs_bootdhcp.c nfsdiskless.h Log Message: change nfs_boot_sendrecv to take sockaddr_in * instead of mbuf * fixes m_serv (single mbuf leak) leak in kern/subr_tftproot.c To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/kern/subr_tftproot.c cvs rdiff -u -r1.40 -r1.41 src/sys/nfs/krpc_subr.c cvs rdiff -u -r1.84 -r1.85 src/sys/nfs/nfs_boot.c cvs rdiff -u -r1.54 -r1.55 src/sys/nfs/nfs_bootdhcp.c cvs rdiff -u -r1.31 -r1.32 src/sys/nfs/nfsdiskless.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/subr_tftproot.c diff -u src/sys/kern/subr_tftproot.c:1.15 src/sys/kern/subr_tftproot.c:1.16 --- src/sys/kern/subr_tftproot.c:1.15 Sun May 10 18:55:22 2015 +++ src/sys/kern/subr_tftproot.c Thu May 21 02:04:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_tftproot.c,v 1.15 2015/05/10 18:55:22 rtr Exp $ */ +/* $NetBSD: subr_tftproot.c,v 1.16 2015/05/21 02:04:22 rtr Exp $ */ /*- * Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved. @@ -39,7 +39,7 @@ #include "opt_md.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.15 2015/05/10 18:55:22 rtr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.16 2015/05/21 02:04:22 rtr Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -207,7 +207,7 @@ tftproot_getfile(struct tftproot_handle struct socket *so = NULL; struct mbuf *m_serv = NULL; struct mbuf *m_outbuf = NULL; - struct sockaddr_in *sin; + struct sockaddr_in sin; struct tftphdr *tftp; size_t packetlen, namelen; int error = -1; @@ -233,11 +233,8 @@ tftproot_getfile(struct tftproot_handle /* * Set server address and port */ - m_serv = m_get(M_WAIT, MT_SONAME); - m_serv->m_len = sizeof(*sin); - sin = mtod(m_serv, struct sockaddr_in *); - memcpy(sin, &trh->trh_nd->nd_root.ndm_saddr, sizeof(*sin)); - sin->sin_port = htons(IPPORT_TFTP); + memcpy(&sin, &trh->trh_nd->nd_root.ndm_saddr, sizeof(sin)); + sin.sin_port = htons(IPPORT_TFTP); /* * Set send buffer, prepare the TFTP packet @@ -268,9 +265,8 @@ tftproot_getfile(struct tftproot_handle /* * Perform the file transfer */ - sin = (struct sockaddr_in *)&trh->trh_nd->nd_root.ndm_saddr; printf("tftproot: download %s:%s ", - inet_ntoa(sin->sin_addr), trh->trh_nd->nd_bootfile); + inet_ntoa(sin.sin_addr), trh->trh_nd->nd_bootfile); do { /* @@ -287,7 +283,7 @@ tftproot_getfile(struct tftproot_handle * We get the sender address here, which should be * the same server with a different port */ - if ((error = nfs_boot_sendrecv(so, m_serv, NULL, m_outbuf, + if ((error = nfs_boot_sendrecv(so, &sin, NULL, m_outbuf, tftproot_recv, NULL, &m_serv, trh, l)) != 0) { DPRINTF(("%s():%d sendrecv failed %d\n", __func__, __LINE__, error)); Index: src/sys/nfs/krpc_subr.c diff -u src/sys/nfs/krpc_subr.c:1.40 src/sys/nfs/krpc_subr.c:1.41 --- src/sys/nfs/krpc_subr.c:1.40 Sat May 9 18:12:19 2015 +++ src/sys/nfs/krpc_subr.c Thu May 21 02:04:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: krpc_subr.c,v 1.40 2015/05/09 18:12:19 rtr Exp $ */ +/* $NetBSD: krpc_subr.c,v 1.41 2015/05/21 02:04:22 rtr Exp $ */ /* * Copyright (c) 1995 Gordon Ross, Adam Glass @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: krpc_subr.c,v 1.40 2015/05/09 18:12:19 rtr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: krpc_subr.c,v 1.41 2015/05/21 02:04:22 rtr Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -219,8 +219,8 @@ krpc_call(struct sockaddr_in *sa, u_int /* from_p: output */ { struct socket *so; - struct sockaddr_in *sin; - struct mbuf *m, *nam, *mhead, *from; + struct sockaddr_in sin; + struct mbuf *m, *mhead, *from; struct rpc_call *call; struct rpc_reply *reply; int error, len; @@ -235,7 +235,7 @@ krpc_call(struct sockaddr_in *sa, u_int return (EAFNOSUPPORT); /* Free at end if not null. */ - nam = mhead = NULL; + mhead = NULL; from = NULL; /* @@ -274,10 +274,7 @@ krpc_call(struct sockaddr_in *sa, u_int /* * Setup socket address for the server. */ - nam = m_get(M_WAIT, MT_SONAME); - sin = mtod(nam, struct sockaddr_in *); - memcpy((void *)sin, (void *)sa, - (nam->m_len = sa->sin_len)); + sin = *sa; /* * Prepend RPC message header. @@ -314,7 +311,7 @@ krpc_call(struct sockaddr_in *sa, u_int mhead->m_pkthdr.len = len; mhead->m_pkthdr.rcvif = NULL; - error = nfs_boot_sendrecv(so, nam, NULL, mhead, krpccheck, &m, &from, + error = nfs_boot_sendrecv(so, &sin, NULL, mhead, krpccheck, &m, &from, &xid, l); if (error) goto out; @@ -383,7 +380,6 @@ krpc_call(struct sockaddr_in *sa, u_int } out: - if (nam) m_freem(nam); if (mhead) m_freem(mhead); if (from) m_freem(from); soclose(so); Index: src/sys/nfs/nfs_boot.c diff -u src/sys/nfs/nfs_boot.c:1.84 src/sys/nfs/nfs_boot.c:1.85 --- src/sys/nfs/nfs_boot.c:1.84 Sat May 9 15:22:47 2015 +++ src/sys/nfs/nfs_boot.c Thu May 21 02:04:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_boot.c,v 1.84 2015/05/09 15:22:47 rtr Exp $ */ +/* $NetBSD: nfs_boot.c,v 1.85 2015/05/21 02:04:22 rtr Exp $ */ /*- * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.84 2015/05/09 15:22:47 rtr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.85 2015/05/21 02:04:22 rtr Exp $"); #ifdef _KERNEL_OPT #include "opt_nfs.h" @@ -425,7 +425,7 @@ nfs_boot_sobind_ipport(struct socket *so #define TOTAL_TIMEOUT 30 /* seconds */ int -nfs_boot_sendrecv(struct socket *so, struct mbuf *nam, +nfs_boot_sendrecv(struct socket *so, struct sockaddr_in *nam, int (*sndproc)(struct mbuf *, void *, int), struct mbuf *snd, int (*rcvproc)(struct mbuf **, void *), @@ -468,7 +468,7 @@ send_again: error = ENOBUFS; goto out; } - error = (*so->so_send)(so, mtod(nam, struct sockaddr *), NULL, + error = (*so->so_send)(so, (struct sockaddr *)nam, NULL, m, NULL, 0, lwp); if (error) { printf("nfs_boot: sosend: %d\n", error); Index: src/sys/nfs/nfs_bootdhcp.c diff -u src/sys/nfs/nfs_bootdhcp.c:1.54 src/sys/nfs/nfs_bootdhcp.c:1.55 --- src/sys/nfs/nfs_bootdhcp.c:1.54 Sat May 9 18:12:19 2015 +++ src/sys/nfs/nfs_bootdhcp.c Thu May 21 02:04:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_bootdhcp.c,v 1.54 2015/05/09 18:12:19 rtr Exp $ */ +/* $NetBSD: nfs_bootdhcp.c,v 1.55 2015/05/21 02:04:22 rtr Exp $ */ /*- * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nfs_bootdhcp.c,v 1.54 2015/05/09 18:12:19 rtr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_bootdhcp.c,v 1.55 2015/05/21 02:04:22 rtr Exp $"); #ifdef _KERNEL_OPT #include "opt_nfs_boot.h" @@ -486,8 +486,8 @@ bootpc_call(struct nfs_diskless *nd, str struct ifnet *ifp = nd->nd_ifp; static u_int32_t xid = ~0xFF; struct bootp *bootp; /* request */ - struct mbuf *m, *nam; - struct sockaddr_in *sin; + struct mbuf *m; + struct sockaddr_in sin; int error; const u_char *haddr; u_char hafmt, halen; @@ -505,7 +505,7 @@ bootpc_call(struct nfs_diskless *nd, str * and free each at the end if not null. */ bpc.replybuf = NULL; - m = nam = NULL; + m = NULL; /* Record our H/W (Ethernet) address. */ { const struct sockaddr_dl *sdl = ifp->if_sadl; @@ -585,12 +585,10 @@ bootpc_call(struct nfs_diskless *nd, str /* * Setup socket address for the server. */ - nam = m_get(M_WAIT, MT_SONAME); - sin = mtod(nam, struct sockaddr_in *); - sin->sin_len = nam->m_len = sizeof(*sin); - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = INADDR_BROADCAST; - sin->sin_port = htons(IPPORT_BOOTPS); + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_BROADCAST; + sin.sin_port = htons(IPPORT_BOOTPS); /* * Allocate buffer used for request @@ -635,7 +633,7 @@ bootpc_call(struct nfs_diskless *nd, str bpc.dhcp_ok = 0; #endif - error = nfs_boot_sendrecv(so, nam, bootpset, m, + error = nfs_boot_sendrecv(so, &sin, bootpset, m, bootpcheck, NULL, NULL, &bpc, lwp); if (error) goto out; @@ -662,7 +660,7 @@ bootpc_call(struct nfs_diskless *nd, str bpc.expected_dhcpmsgtype = DHCPACK; - error = nfs_boot_sendrecv(so, nam, bootpset, m, + error = nfs_boot_sendrecv(so, &sin, bootpset, m, bootpcheck, NULL, NULL, &bpc, lwp); if (error) goto out; @@ -688,8 +686,6 @@ out: free(bpc.replybuf, M_DEVBUF); if (m) m_freem(m); - if (nam) - m_freem(nam); soclose(so); return (error); } Index: src/sys/nfs/nfsdiskless.h diff -u src/sys/nfs/nfsdiskless.h:1.31 src/sys/nfs/nfsdiskless.h:1.32 --- src/sys/nfs/nfsdiskless.h:1.31 Fri Mar 27 07:18:11 2015 +++ src/sys/nfs/nfsdiskless.h Thu May 21 02:04:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: nfsdiskless.h,v 1.31 2015/03/27 07:18:11 hikaru Exp $ */ +/* $NetBSD: nfsdiskless.h,v 1.32 2015/05/21 02:04:22 rtr Exp $ */ /*- * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ void nfs_boot_flushrt (struct ifnet *); int nfs_boot_setrecvtimo (struct socket *); int nfs_boot_enbroadcast (struct socket *); int nfs_boot_sobind_ipport (struct socket *, uint16_t, struct lwp *); -int nfs_boot_sendrecv (struct socket *, struct mbuf *, +int nfs_boot_sendrecv (struct socket *, struct sockaddr_in *, int (*)(struct mbuf*, void*, int), struct mbuf*, int (*)(struct mbuf**, void*), struct mbuf**, struct mbuf**, void*, struct lwp *);