内核完全注释1makefileUnix系统

时间:2022-04-30 12:42:16 其他范文 收藏本文 下载本文

“今天不要熬夜”为你分享5篇“内核完全注释1makefileUnix系统”,经本站小编整理后发布,但愿对你的工作、学习、生活带来方便。

内核完全注释1makefileUnix系统

篇1:内核完全注释1makefileUnix系统

Makefile文件 Makefile文件相当于程序编译过程中的批处理文件,是工具程序make运行时的输入数据文件,make程序是使用Makefile数据文件和代码的最后修改时间(last-modification-time)来确定哪些文件需要进行更新,对与每一个需要更新的文件它会根据Makefile

Makefile文件

Makefile文件相当于程序编译过程中的批处理文件,是工具程序make运行时的输入数据文件。make程序是使用Makefile数据文件和代码的最后修改时间(last-modification-time)来确定哪些文件需要进行更新,对与每一个需要更新的文件它会根据Makefile中的信息发出相应的命令。

Makefile文件的作用:指示make程序最终使用独立编译连接成的tools/目录中的build执行程序将所有内核编译代码连接合并成一个可运行的内核映象文件image,具体是对boot/中的bootsect.s,setup.s使用8086汇编器进行编译,并连接成模块system,再用build工具将这3块组合成一个内核映象image

head,main,kernel,mm,fs.lib==>system+bootsect+setup(通过bulid工具)====>内核映象文件 image

当make重新编译一个程序时,被修改过的C程序,必须被重新编译.如果一个头文件被修改过了,那么包含或用到这个头文件的程序都将被重新编译,每次编译的结果都产生一个于源文件对应

的目标文件(object file).最终所有的头文件都被编译过了,那么所有目标文件,不管是刚编译的,或是以前编译好生成的,都必须被重新连接成一个新的可执行程序.

简单的Makefile的命名规则:

目标(target)...: 先决条件(prerequistes)

命令(command)

....................

....................

目标通常是程序生成的一个文件名,目标也可以是所要采取活动的名字(如,clean),先决条件是一个文件,用作产生目标的输入,命令是make执行需要的操作!

*:需要再命令行前输入制表符!

原文转自:http://www.ltesting.net

篇2:编译内核怎么弄?Unix系统

安装好了freebsd4,7 我按照下面的做了 cd/sys/i386/conf cpGENERIC./kernel_ipfw 用编辑器打开kernel_IPFW这个文本文件,在该文件里加入以下内容: optionsIPFIREWALL//通知操作系统的内核检查每个IP数据包,将它们与规则集进行比较 optionsIPDIVERT//启用

安装好了freebsd4。7

我按照下面的做了

cd /sys/i386/conf

cp GENERIC ./kernel_ipfw

用编辑器打开kernel_IPFW这个文本文件,在该文件里加入以下内容:

optionsIPFIREWALL        //通知操作系统的内核检查每个IP数据包,将它们与规则集进行比较

optionsIPDIVERT        //启用由ipfw divert使用的转向IP套接字。这一选项需要与natd联合使用。

optionsIPFIREWALL_VERBOSE       //向系统的注册程序发送注册信息包。

optionsIPFIREWALL_VERBOSE_LIMIT=100       //限制一台机器注册的次数。

optionsIPSTEALTH        //启动支持秘密转发的代码,这一选项在使防火墙不被traceroute和类似工具发现时很有用。

optionsACCEPT_FILTER_DATA

optionsACCEPT_FILTER_HTTP      //接受过滤器中的静态连接

optionsICMP_BANDLIM        //ICMP_BANDLIM根据带宽限制产生icmp错误。一般情况下我们需要这个选项,它有助于你的系统免受D.O.S.攻击。

把以上参数加入以后保存kernel_ipfw文件。

上面的做好了 接下去输入

make depend

提示  [color=red:262b4419a5]make dont know how to make depend . stop [/color:262b4419a5] 我不知道盖怎么弄?

我看了论坛以前的帖子有相关的问题但是又不懂

[color=green:262b4419a5]--------------------------------------------------------------------------------

不知道你的source是不是装了

你把你的kernel文件重新换个名字,比如IPFW,再按我的方法试一下.

注意别敲错命令,我发现你的kernel拼写有错误

_________________

Free is NOT cheap.

I love free

I love FreeBSD [/color:262b4419a5]

我的问题是不是也是名字的问题?要怎么才能改名?

cd ../../compile/kernel_IPFW

make

make install

stevensli 回复于:-03-03 13:52:00Procedure 1. Building a kernel the ``traditional'' way

Run config(to generate the kernel source code.

# /usr/sbin/config MYKERNEL

Change into the build directory.

# cd ../compile/MYKERNEL

For FreeBSD version prior to 5.0, use instead:

# cd ../../compile/MYKERNEL

Compile the kernel.

# make depend

# make

Install the new kernel.

# make install

Procedure 2. Building a kernel the ``new'' way

Change to the /usr/src directory.

# cd /usr/src

Compile the kernel.

# make buildkernel KERNCONF=MYKERNEL

Install the new kernel.

# make installkernel KERNCONF=MYKERNEL

Note: In FreeBSD 4.2 and older you must replace KERNCONF= with KERNEL=. 4.2-STABLE thatwasfetched before Feb 2nd,  does not recognize KERNCONF=.

henkon 回复于:2003-03-03 13:31:52config 内核文件名

夜猫子 回复于:2003-03-03 13:33:26你要先在/sys/i386/conf下运行

config ./kernel_ipfw

然后

cd ../../compile/kernel_IPFW

make depend &&  make && make install

quakelee 回复于:2003-03-03 18:43:55你们就不能提供一个有创意的方法,比如我就会用

cd /usr/src

make buildkernel KERNCONF=kernel_IPFW

make installkernel KERNCONF=kernel_IPFW

bluepunk 回复于:2003-03-03 18:30:46#pwd

/sys/i386/conf

config ./kernel_ipfw

#cd ../../compile/kernel_IPFW

#make depend all install

dabeck 回复于:2003-03-27 10:14:06人家不是说了嘛,

ihweb 回复于:2003-03-27 10:33:34[quote:9a6daea6b1=“quakelee”]你们就不能提供一个有创意的方法,比如我就会用

cd /usr/src

make buildkernel KERNCONF=kernel_IPFW

make installkernel KERNCONF=kernel_IPFW[/quote:9a6daea6b1]

有空可真的要试试这种编译内核的方法。

onedaycj 回复于:2003-03-29 16:16:56[quote:f48fed359c=“ihweb”]

有空可真的要试试这种编译内核的方法。[/quote:f48fed359c]

好慢呢....

quakelee 回复于:2003-03-29 23:48:55什么叫做有空,没空才用我的方法,因为省掉了

config mykern

cd ../../compile/mykern

make depend

make

这四步,而用一步解决了

原文转自:http://www.ltesting.net

篇3:FreeBSD手册――配置FreeBSD内核Unix系统

转自中文FreeBSD用户组 http://journal.cnfug.org/issue8/000045.html#45 FreeBSD手册――配置FreeBSD内核[阅读次数: 1761次] 顾宏军(redarmy) redarmy@ linux aid.com.cn 9 配置FreeBSD 内核 9.1 大纲 9.2 为什么要构建一个定制的内核? 9.3 建立并安装一个

转自中文FreeBSD用户组 http://journal.cnfug.org/issue8/000045.html#45

FreeBSD手册――配置FreeBSD内核  [阅读次数: 1761次]

顾宏军(redarmy) linuxaid.com.cn>

9 配置FreeBSD 内核

9.1 大纲

9.2 为什么要构建一个定制的内核?

9.3 建立并安装一个定制的内核

9.4 配置文件

9.5 建立设备节点

9.6 出现问题如何解决

----------------------------------------------------------------------

Chapter 9 配置FreeBSD 内核

由Jake Hamby最初投稿,由Jim Mock更新

9.1 大纲

内核是FreeBSD系统的核心,它用来进行内存管理,安全控制,网络,磁盘访问等等。而有

时你需要重新配置和编译你的内核。

读完这一章,你将知道以下内容:

* 为什么需要建构一个定制的内核.

* 怎么样写一个内核配置文件,或修改一现有的配置文件.

* 怎么样使用内核配置文件创造并构建一新内核.

* 怎么样安装一个新内核.

* 在需要的情况下,怎么样在/dev 中创建设备文件.

* 出问题后,如何解决所出现的问题.

----------------------------------------------------------------------

9.2 为什么要构建一个定制的内核?

以前,freebsd的内核是一个宏内核。这意味着,内核是一个支持固定数量设备的大

型程序。如果你想改变内核的行为,就必须从新编译内核,并用新内核从新启动系统。.

如今,freebsd内核正快速向一模块化方向迁移;也就是说核由模块组成,内核功能

由模块实现,我们能根据需要随时加载或卸载功能模块。这使得内核能迅速识别新硬件

(如笔记本电脑上的PCMCIA卡),能容易的在内核中加入最初编译的内核所不具备的功

能,

这就是所说的模块化内核。通俗的讲,就是KLDs。.

尽管如此,仍然有必要做一些静态的内核编译。因为在某些情况下,功能性相互交叉,

无法实现动态加载;也有可能就是还没有人写出实现这种功能的内核可动态加载的模块.

构建一个定制的内核几乎是每一个UNIX用户都该有的重要能力之一。这样做虽然会

消耗一定的时间,但它将会对你的FreeBSD 系统带来很多好处。定制的内核将只包含对

你PC的硬件设备的支持,这点不象需支持很广泛的硬件设备的GENERIC 内核。它会带来

许多好处:

* 更短的启动时间。因为内核只检测你机器上有的硬件,那么系统启动所需的时间

将大大减少。

* 较少的内存使用量。一个定制的内核通常会比GENERIC 内核使用更少的内存。这

一点很重要,因为内核必须始终驻留实存,占用内存。所以,一个定制的内核对于内存较

少的机器来说尤为重要.

* 额外的硬件支持。一个定制的内核允许你为 声卡等不为GENERIC 内核所支持的

设备提供支持.

----------------------------------------------------------------------

9.3 建立并安装一个定制的内核

首先,我们粗略浏览一下构建内核的目录。所有提及的目录都是相对于/usr/src/sys

而言的,它们也可以通 过/sys 访问。这里的子目录代表内核的不同部分。但对我们而言,

最重要的是/arch/conf ,在这儿你可以定 制内核的配置,然后进行编译,它是所译内核

的存放地。这里的arch 也可能是i386,alpha,或pc98(pc硬件的 一种体系,在日本比较流

行) 。在一个特殊的体系结构目录内的所有代码是这个体系结构所独有的;其它部 分的

代码是所有平台共享的。注意一下目录的逻辑结构,所有支持的设备、文件系统和选项,

等都在它们各自 的子目录下。FreeBSD 5.x及以后的版本已经支持sparc64,还有一些其

它平台的支持正在开发中。

注意:如果你的系统没有/usr/src/sys 目录,这表明内核源代码就没有被安装。最

容易的安装方式是以root 的身份运行/stand/sysinstall ,然后选择

configure->Distributions->src->sys。要是你不喜欢用sysinstall,但有freebsd

的官方安装盘,那么你可 以用以下的命令安装源代码:

# mount /cdrom

# mkdir -p /usr/src/sys

# ln -s /usr/src/sys /sys

# cat /cdrom/src/ssys.[a-d]* | tar -xzvf -

原文转自:http://www.ltesting.net

篇4:FreeBSD内核配置Unix系统

我的机器内核配置文件, machinei386 cpuI686_CPU optionsCPU_ENABLE_SSE optionsPQ_MEDIUMCACHE optionsCPU_UPGRADE_HW_CACHE options PANIC_REBOOT_WAIT_TIME=16 ptionsCONSPEED=115200 optionsSC_NO_HISTORY optionsSC_DISABLE_REBOOT optionsSC_DISABLE_

我的机器内核配置文件。

machine i386

cpu I686_CPU

options CPU_ENABLE_SSE

options PQ_MEDIUMCACHE

options CPU_UPGRADE_HW_CACHE

options PANIC_REBOOT_WAIT_TIME=16

options CONSPEED=115200

options SC_NO_HISTORY

options SC_DISABLE_REBOOT

options SC_DISABLE_DDBKEY

options MAXMEM=“(256*1024)”

options MAXDSIZ=“(256*1024*1024)”

options MAXSSIZ=“(256*1024*1024)”

options DFLDSIZ=“(256*1024*1024)”

ident TRAVEL

maxusers 0

#makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols

#options MATH_EMULATE #Support for x87 emulation

options INET #InterNETworking

#options INET6 #IPv6 communications protocols

options FFS #Berkeley Fast Filesystem

options FFS_ROOT #FFS usable as root device [keep this!]

options SOFTUPDATES #Enable FFS soft updates support

options UFS_DIRHASH #Improve performance on big directories

#options MFS #Memory Filesystem

#options MD_ROOT #MD is a potential root device

#options NFS #Network Filesystem

#options NFS_ROOT #NFS usable as root device, NFS required

#options MSDOSFS #MSDOS Filesystem

options CD9660 #ISO 9660 Filesystem

#options CD9660_ROOT #CD-ROM usable as root, CD9660 required

options PROCFS #Process filesystem

options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!]

#options SCSI_DELAY=15000 #Delay (in ms) before probing SCSI

options UCONSOLE #Allow users to grab the console

options USERCONFIG #boot -c editor

options VISUAL_USERCONFIG #visual boot -c editor

options KTRACE #ktrace(1) support

options SYSVSHM #SYSV-style. shared memory

options SYSVMSG #SYSV-style. message queues

options SYSVSEM #SYSV-style. semaphores

options P1003_1B #Posix P1003_1B real-time extensions

options _KPOSIX_PRIORITY_SCHEDULING

options ICMP_BANDLIM #Rate limit bad replies

options KBD_INSTALL_CDEV # install a CDEV entry in /dev

options AHC_REG_PRETTY_PRINT # Print register bitfields in debug

# output. Adds ~128k to driver.

options AHD_REG_PRETTY_PRINT # Print register bitfields in debug

# output. Adds ~215k to driver.

options SHMMAXPGS=65536

options SEMMNI=40

options SEMMNS=240

options SEMUME=40

options SEMMNU=120

options QUOTA

options USER_LDT

options DEVICE_POLLING

options HZ=1000

options NMBCLUSTERS=8192

options RANDOM_IP_ID

options IPSTEALTH

options IPFILTER

options IPFILTER_LOG

options IPFILTER_DEFAULT_BLOCK

options ACCEPT_FILTER_DATA

options ACCEPT_FILTER_HTTP

device pcm

# To make an SMP kernel, the next two are needed

#options SMP # Symmetric MultiProcessor Kernel

#options APIC_IO # Symmetric (APIC) I/O

# To support HyperThreading, HTT is needed in addition to SMP and APIC_IO

#options HTT # HyperThreading Technology

device isa

#device eisa

device pci

# Floppy drives

#device fdc0 at isa? port IO_FD1 irq 6 drq 2

#device fd0 at fdc0 drive 0

#device fd1 at fdc0 drive 1

#

# If you have a Toshiba Libretto with its Y-E Data PCMCIA floppy,

# don't use the above line for fdc0 but the following one:

#device fdc0

# ATA and ATAPI devices

#device ata0 at isa? port IO_WD1 irq 14

#device ata1 at isa? port IO_WD2 irq 15

device ata

device atadisk # ATA disk drives

device atapicd # ATAPI CDROM drives

#device atapifd # ATAPI floppy drives

#device atapist # ATAPI tape drives

#options ATA_STATIC_ID #Static device numbering

# SCSI Controllers

#device ahb # EISA AHA1742 family

#device ahc # AHA2940 and onboard AIC7xxx devices

#device ahd # AHA39320/29320 and onboard AIC79xx devices

#device amd # AMD 53C974 (Tekram DC-390(T))

#device isp # Qlogic family

#device mpt # LSI-Logic MPT/Fusion

#device ncr # NCR/SymbiosLogic

#device sym # NCR/Symbios Logic (newer chipsets)

#options SYM_SETUP_LP_PROBE_MAP=0x40

# Allow ncr to attach legacy NCR devices when

# both sym and ncr are configured

#device adv0 at isa?

#device adw

#device bt0 at isa?

#device aha0 at isa?

#device aic0 at isa?

#device ncv # NCR 53C500

#device nsp # Workbit Ninja SCSI-3

#device stg # TMC 18C30/18C50

# SCSI peripherals

#device scbus # SCSI bus (required)

#device da # Direct Aclearcase/“ target=”_blank“ >ccess (disks)

#device sa # Sequential Access (tape etc)

#device cd # CD

#device pass # Passthrough device (direct SCSI access)

# RAID controllers interfaced to the SCSI subsystem

#device asr # DPT SmartRAID V, VI and Adaptec SCSI RAID

#device dpt # DPT Smartcache - See LINT for options!

#device iir # Intel Integrated RAID

#device mly # Mylex AcceleRAID/eXtremeRAID

#device ciss # Compaq SmartRAID 5* series

# RAID controllers

#device aac # Adaptec FSA RAID, Dell PERC2/PERC3

##device aacp # SCSI passthrough for aac (requires CAM)

#device ida # Compaq Smart RAID

#device amr # AMI MegaRAID

#device mlx # Mylex DAC960 family

#device twe # 3ware Escalade

# atkbdc0 controls both the keyboard and the PS/2 mouse

device atkbdc0 at isa? port IO_KBD

device atkbd0 at atkbdc? irq 1 flags 0x1

#device psm0 at atkbdc? irq 12

device vga0 at isa?

# splash screen/screen saver

pseudo-device splash

# syscons is the default console driver, resembling an SCO console

device sc0 at isa? flags 0x100

# Enable this and PCVT_FREEBSD for pcvt vt220 compatible console driver

#device vt0 at isa?

#options XSERVER # support for X server on a vt console

#options FAT_CURSOR # start with block cursor

# If you have a ThinkPAD, uncomment this along with the rest of the PCVT lines

#options PCVT_SCANSET=2 # IBM keyboards are non-std

device agp # support several AGP chipsets

# Floating point support - do not disable.

device npx0 at nexus? port IO_NPX irq 13

# Power management support (see LINT for more options)

#device apm0 at nexus? disable flags 0x20 # Advanced Power Management

# PCCARD (PCMCIA) support

#device card

#device pcic0 at isa? irq 0 port 0x3e0 iomem 0xd0000

#device pcic1 at isa? irq 0 port 0x3e2 iomem 0xd4000 disable

# Serial (COM) ports

device sio0 at isa? port IO_COM1 flags 0x10 irq 4

device sio1 at isa? port IO_COM2 irq 3

#device sio2 at isa? disable port IO_COM3 irq 5

#device sio3 at isa? disable port IO_COM4 irq 9

# Parallel port

device ppc0 at isa? irq 7

device ppbus # Parallel port bus (required)

device lpt # Printer

#device plip # TCP/IP over parallel

#device ppi # Parallel port interface device

##device vpo # Requires scbus and da

# PCI Ethernet NICs.

#device de # DEC/Intel DC21x4x (``Tulip'')

#device em # Intel PRO/1000 adapter Gigabit Ethernet Card (``Wiseman'')

#device txp # 3Com 3cR990 (``Typhoon'')

#device vx # 3Com 3c590, 3c595 (``Vortex'')

# PCI Ethernet NICs that use the common MII bus controller code.

# NOTE: Be sure to keep the 'device miibus' line in order to use these NICs!

device miibus # MII bus support

#device dc # DEC/Intel 21143 and various workalikes

#device fxp # Intel EtherExpress PRO/100B (82557, 82558)

#device pcn # AMD Am79C97x PCI 10/100 NICs

device rl # RealTek 8129/8139

#device sf # Adaptec AIC-6915 (``Starfire'')

#device sis # Silicon Integrated Systems SiS 900/SiS 7016

#device ste # Sundance ST201 (D-Link DFE-550TX)

#device tl # Texas Instruments ThunderLAN

#device tx # SMC EtherPower II (83c170 ``EPIC'')

#device vr # VIA Rhine, Rhine II

#device wb # Winbond W89C840F

#device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'')

#device bge # Broadcom BCM570x (``Tigon III'')

# ISA Ethernet NICs.

# 'device ed' requires 'device miibus'

device ed0 at isa? disable port 0x280 irq 10 iomem 0xd8000

#device ex

#device ep

#device fe0 at isa? disable port 0x300

# Xircom Ethernet

#device xe

# PRISM I IEEE 802.11b wireless NIC.

#device awi

# WaveLAN/IEEE 802.11 wireless NICs. Note: the WaveLAN/IEEE really

# exists only as a PCMCIA device, so there is no ISA attachment needed

# and resources will always be dynamically assigned by the pccard code.

#device wi

# Aironet 4500/4800 802.11 wireless NICs. Note: the declaration below will

# work for PCMCIA and PCI cards, as well as ISA cards set to ISA PnP

# mode (the factory default). If you set the switches on your ISA

# card for a manually chosen I/O address and IRQ, you must specify

# those parameters here.

#device an

# The probe order of these is presently determined by i386/isa/isa_compat.c.

#device ie0 at isa? disable port 0x300 irq 10 iomem 0xd0000

##device le0 at isa? disable port 0x300 irq 5 iomem 0xd0000

#device lnc0 at isa? disable port 0x280 irq 10 drq 0

#device cs0 at isa? disable port 0x300

#device sn0 at isa? disable port 0x300 irq 10

# Pseudo devices - the number indicates how many units to allocate.

pseudo-device loop # Network loopback

pseudo-device ether # Ethernet support

#pseudo-device sl 1 # Kernel SLIP

pseudo-device ppp 1 # Kernel PPP

pseudo-device tun # Packet tunnel.

pseudo-device pty # Pseudo-ttys (telnet etc)

pseudo-device md # Memory ”disks“

#pseudo-device gif # IPv6 and IPv4 tunneling

#pseudo-device faith 1 # IPv6-to-IPv4 relaying (translation)

# The `bpf' pseudo-device enables the Berkeley Packet Filter.

# Be aware of the administrative consequences of enabling this!

pseudo-device bpf #Berkeley packet filter

# USB support

device uhci # UHCI PCI->USB interface

device ohci # OHCI PCI->USB interface

device usb # USB Bus (required)

#device ugen # Generic

#device uhid # ”Human Interface Devices“

#device ukbd # Keyboard

#device ulpt # Printer

#device umass # Disks/Mass storage - Requires scbus and da

device ums # Mouse

#device uscanner # Scanners

#device urio # Diamond Rio MP3 Player

# USB Ethernet, requires mii

#device aue # ADMtek USB ethernet

#device cue # CATC USB ethernet

#device kue # Kawasaki LSI USB ethernet

# FireWire support

#device firewire # FireWire bus code

#device sbp # SCSI over FireWire (Requires scbus and da)

#device fwe # Ethernet over FireWire (non-standard!)

原文转自:http://www.ltesting.net

篇5:OpenBSD 内核 PPPoE 补丁Unix系统

前段时间用新装的OpenBSD(3.7 Stable)做家里的NAT ,使用Kernel Mode 的 PPPoE连接到 电信 的ADSL,结果系统在大流量的时候内核会cr ash,经过几天的调裕?沼谡业搅�Bug 所在,现在问题已经解决,并且工作非常良好, 前段时间用新装的OpenBSD(3.7 Stable

前段时间用新装的OpenBSD(3.7 Stable)做家里的NAT,使用Kernel Mode 的 PPPoE连接到电信的ADSL,结果系统在大流量的时候内核会crash,经过几天的调裕?沼谡业搅�Bug 所在,现在问题已经解决,并且工作非常良好。

前段时间用新装的OpenBSD(3.7 Stable)做家里的NAT,使用Kernel Mode 的 PPPoE连接到电信的ADSL,结果系统在大流量的时候内核会crash,经过几天的调裕?沼谡业搅�Bug 所在,现在问题已经解决,并且工作非常良好。

这是crash时的信息:

uvm_fault(0xd0291580, 0xdee80000, 0, 1) -> e

kernel: page fault trap, code = 0

stopped at bcopy+0x1a: repe movsl (%esi), %es:(%edi)

ddb>

经过长时间的调试找到问题是出在/sys/net/if_spppsubr.c中,相关的代码如下:

sppp_input(struct ifnet *ifp,struct mbuf *m) 中的

struct ppp_header *h, ht;

if (sp->pp_flags & PP_NOFRAMING) {

memcpy(&ht.protocol, mtod(m, void *), 2);

m_adj(m, 2);

ht.control = PPP_UI;

ht.address = PPP_ALLSTATIONS;

h = &ht;

} else {

/* Get PPP header. */

h = mtod (m, struct ppp_header*);

m_adj (m, PPP_HEADER_LEN);

}

.....

switch (ntohs (h->protocol)) {

default:

if (sp->state[IDX_LCP] == STATE_OPENED)

sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, m->m_pkthdr.len + 2,

&h->protocol);

在 sppp_cp_send 函数中有一个 bcopy 调用:

if (len)

bcopy (data, lh+1, len);

当 (sp->pp_flags & PP_NOFRAMING) 为真时, *h 将指向 ht (即结构

ppp_header), 接下来当调用 sppp_cp_send(sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, m->m_pkthdr.len + 2, &h->protocol) 时会产生一个错误的bcopy调用,即:

bcopy(&h->protocol, lh+1, m->m_pkthdr.len + 2)

此时 &h->protocol 的有效内容只有 2 个字节(因为struct ppp_header只分配4个字节),而m->m_pkthdr.len + 2 将永远 >= 2,所以此时将会出现非法的内存访问,因而就可能造成kernel crash。

修复这个bug只要将m->m_pkthdr.len + 2,改为 2 便可,下面是这一简单的修复方法:

将:

if (sp->state[IDX_LCP] == STATE_OPENED)

sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, m->m_pkthdr.len + 2,

&h->protocol);

改为:

if (sp->state[IDX_LCP] == STATE_OPENED)

{

if (sp->pp_flags & PP_NOFRAMING)

sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, 2,

&h->protocol);

else

sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, m->m_pkthdr.len + 2,

&h->protocol);

}

另外,我看了一下netbsd的内核级PPPoE实现,好像也存在同样的问题,代码同样在 /sys/net/if_spppsubr.c (Revision: 1.85):

u_int16_t prot = htons(protocol);

sppp_cp_send(sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2,

&prot);

不过由于我这边没有测试环境,所以无法证实这个问题,希望有测试环境的朋友帮忙测试一下。

我将这个问题提交给了openbsd的开发者,Can Erkin Acar 提供了一个src patch,我在机器上经过长时间的测试,在使用这个patch后没有再出现crash的情况,Can Erkin Acar已经将其提交到openbsd-current中(if_spppsubr.c revision 1.36) ^_^,后附Can Erkin Acar提供的Patch,希望对你有用:

Index: if_spppsubr.c

===================================================================

RCS file: /cvs/src/sys/net/if_spppsubr.c,v

retrieving revision 1.35

diff -u -p -u -p -r1.35 if_spppsubr.c

--- if_spppsubr.c   3 Aug 2005 21:50:21 -0000   1.35

+++ if_spppsubr.c   9 Aug 2005 06:09:20 -0000

@@ -458,6 +458,7 @@ sppp_input(struct ifnet *ifp, struct mbu

struct ifqueue *inq = 0;

struct sppp *sp = (struct sppp *)ifp;

struct timeval tv;

+   void *prej;

int debug = ifp->if_flags & IFF_DEBUG;

int s;

@@ -483,7 +484,8 @@ sppp_input(struct ifnet *ifp, struct mbu

}

if (sp->pp_flags & PP_NOFRAMING) {

-       memcpy(&ht.protocol, mtod(m, void *), 2);

+       prej = mtod(m, void *);

+       memcpy(&ht.protocol, prej, sizeof(ht.protocol));

m_adj(m, 2);

ht.control = PPP_UI;

ht.address = PPP_ALLSTATIONS;

@@ -491,6 +493,7 @@ sppp_input(struct ifnet *ifp, struct mbu

} else {

/* Get PPP header. */

h = mtod (m, struct ppp_header*);

+       prej = &h->protocol;

m_adj (m, PPP_HEADER_LEN);

}

@@ -511,8 +514,7 @@ sppp_input(struct ifnet *ifp, struct mbu

default:

if (sp->state[IDX_LCP] == STATE_OPENED)

sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

-                   ++sp->pp_seq, m->m_pkthdr.len + 2,

-                   &h->protocol);

+                 ++sp->pp_seq, m->m_pkthdr.len + 2, prej);

相关链接:

if_spppsubr.c Revision 1.36

http://www.openbsd.org/cgi-bin/cvsweb/src/sys/net/if_spppsubr.c?rev=1.36&content-type=text/x-cvsweb-markup

Bug Report PR# 4305:

From mj2@openbsd.org Sun Jul 24 00:13:50 2005

Received: from shear.ucar.edu (shear.ucar.edu [192.43.244.163])

by cvs.openbsd.org (8.13.4/8.12.1) with ESMTP id j6O6Dn2u019400

(version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=FAIL)

for; Sun, 24 Jul 2005 00:13:49 -0600 (MDT)

Received: from shear.ucar.edu (localhost.ucar.edu [127.0.0.1])

by shear.ucar.edu (8.13.4/8.13.3) with ESMTP id j6O6FIup023908

(version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO)

for; Sun, 24 Jul 2005 00:15:18 -0600 (MDT)

Received: (from mj2@localhost)

by shear.ucar.edu (8.13.4/8.13.3/Submit) id j6O6FIR1008133

for gnats@cvs.openbsd.org; Sun, 24 Jul 2005 00:15:18 -0600 (MDT)

Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.199])

by shear.ucar.edu (8.13.4/8.13.3) with ESMTP id j6O6ErSu014880

for; Sun, 24 Jul 2005 00:14:53 -0600 (MDT)

Received: by wproxy.gmail.com with SMTP id i7so791830wra

for; Sat, 23 Jul 2005 23:14:52 -0700 (PDT)

Received: by 10.54.57.21 with SMTP id f21mr442402wra; Sat, 23 Jul 2005 23:14:52 -0700 (PDT)

Received: by 10.54.45.30 with HTTP; Sat, 23 Jul 2005 23:14:52 -0700 (PDT)

Message-Id: <35clearcase/” target=“_blank” >cc614e0507232314354703e5@mail.gmail.com>

Date: Sat, 23 Jul 2005 23:14:52 -0700

From: xiangbo

Reply-To: xiangbo

To: bugs@openbsd.org

Cc: gnats@openbsd.org

Subject: kernel get crash when using the kernel mode PPPoE

>Number:        4305

>Category:      kernel

>Synopsis:      kernel get crash when using the kernel mode PPPoE

>Confidential:  yes

>Severity:      serious

>Priority:      medium

>Responsible:   bugs

>State:         closed

>Quarter:

>Keywords:

>Date-Required:

>Class:         sw-bug

>Submitter-Id:  net

>Arrival-Date:  Sun Jul 24 06:20:02 GMT 2005

>Closed-Date:   Fri Aug 12 15:41:18 MDT 2005

>Last-Modified: Fri Aug 12 15:41:18 MDT 2005

>Originator:    matthew

>Release:       openbsd-3.7-stable 20050717

>Organization:

CNFUG.org

net

>Environment:

System     : OpenBSD 3.7

Architecture: OpenBSD.i386

Machine    : i386

>Description:

Using the kernel mode PPPoE + PF provide NAT service for clients, kernel get

crashed within 20 minutes.

>How-To-Repeat:

Compile a kernel without INET6 support and start up a PPPoE connection and PF

NAT service for some clients, then running ftp downloads on these clients.

If the kernel doesn't get crash, try to run some tasks on the OpenBSD box (for

example: build a kernel or nmap some box).

>Fix:

crash info and trace:

=====================

uvm_fault(0xd0291580, 0xdee80000, 0, 1) -> e

kernel: page fault trap, code = 0

stopped at bcopy+0x1a: repe movsl (%esi), %es:(%edi)

ddb> trace

bcopy(d06bc00,c021,8,1d,5d6,dee89f42,d069d84c,d4a57800) at bcopy+0x1a

sppp_input(d06bc00,d4a57800,1,d069d800,dee89f98) at sppp_input+0x308

pppoeintr(d4a57800,d0681380,44,3c01840a) at pppoeintr+0x841

pppoeintr(27,27,27,27,3c01840a) at pppoeintr+0xd9

Bad frame. pointer: 0xdee89fa0

ddb> print $esi

dee89ffe

ddb> print $edi

d4a57de6

ddb> print $ecx

6

ddb> x/ex $esp,20

0xdeeb6ecc: 2 d4920700 d018fd64 deeb6f42 d492072a

.........

ddb> x/i 0xd018fd64

sppp_cp_send + 0x264: addl x10,%esp

Finally I found the function that make crash is sppp_input(struct ifnet *ifp,

struct mbuf *m) in /sys/net/if_spppsubr.c

struct ppp_header *h, ht;

if (sp->pp_flags & PP_NOFRAMING) {

memcpy(&ht.protocol, mtod(m, void *), 2);

m_adj(m, 2);

ht.control = PPP_UI;

ht.address = PPP_ALLSTATIONS;

h = &ht;

} else {

/* Get PPP header. */

h = mtod (m, struct ppp_header*);

m_adj (m, PPP_HEADER_LEN);

}

.....

switch (ntohs (h->protocol)) {

default:

if (sp->state[IDX_LCP] == STATE_OPENED)

sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, m->m_pkthdr.len + 2,

&h->protocol);

and the bcopy call in function sppp_cp_send(struct sppp *sp, u_short proto,

u_char type, u_char ident, u_short len, void *data):

if (len)

bcopy (data, lh+1, len);

when the (sp->pp_flags & PP_NOFRAMING) is true, *h will point to ht (struct

ppp_header), and following call sppp_cp_send(sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq, m->m_pkthdr.len + 2, &h->protocol) will make a error bcopy call:

bcopy(&h->protocol, lh+1, m->m_pkthdr.len + 2) /* the contents of h->protocol

is 2 byte, (m->m_pkthdr.len + 2) will always >= 2, so there maybe have a

invalid memory access */

BTW: it seems like netbsd's /sys/net/if_spppsubr.c also have this problem,

netbsd's code is (Revision: 1.85):

u_int16_t prot = htons(protocol);

sppp_cp_send(sp, PPP_LCP, PROTO_REJ,

++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2,

&prot);

but I don't have enviroment to proof that.

Follow is a simple diff for /sys/net/if_spppsubr.c

-------------------- CUT HERE ------------------------------------------

--- if_spppsubr.c      Thu Jul 21 07:51:23 2005

+++ if_spppsubr.c.origin       Thu Jul 21 07:49:43 2005

@@ -506,17 +506,10 @@

}

switch (ntohs (h->protocol)) {

default:

-                      if (sp->state[IDX_LCP] == STATE_OPENED) {

-                              if (sp->pp_flags & PP_NOFRAMING)

-                                      sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

-                                              ++sp->pp_seq, 2,

-                                              &h->protocol);

-                              else

-                                      sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

-                                              ++sp->pp_seq, m->m_pkthdr.len +

-                                              &h->protocol);

-                      }

-

+                      if (sp->state[IDX_LCP] == STATE_OPENED)

+                              sppp_cp_send (sp, PPP_LCP, PROTO_REJ,

+                                      ++sp->pp_seq, m->m_pkthdr.len + 2,

+                                      &h->protocol);

if (debug)

log(LOG_DEBUG,

SPP_FMT “invalid input protocol ”

-------------------- CUT HERE ------------------------------------------

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed

State-Changed-By: canacar

State-Changed-When: Fri Aug 12 15:39:55 MDT 2005

State-Changed-Why:

Fixed in -current, fix tested by the submitter, thanks.

>Unformatted:

SENDBUG: -*- sendbug -*-

SENDBUG: Lines starting with `SENDBUG' will be removed automatically, as

SENDBUG: will all comments (text enclosed in `<' and `>').

SENDBUG:

SENDBUG: Choose from the following categories:

SENDBUG:

SENDBUG: system user library documentation ports kernel alpha amd64 arm i386

m68k m88k mips ppc sgi sparc sparc64 vax

SENDBUG:

SENDBUG:

To: gnats@openbsd.org

Subject: kernel get crash when using the kernel mode PPPoE

From: matthew@cnfug.org

Cc:

Reply-To: matthew@cnfug.org

X-sendbug-version: 3.97

原文转自:http://www.ltesting.net

0202 日的学习内容Windows系统

Solaris学习笔记Windows系统

网络管理员面试题

Unix系列shell程序编写Windows系统

网络管理员协议书

实例讲解在Linux下安装nvidia显卡驱动Linux

Linux UDP反弹shell脚本脚本安全

SA239考前总结(14章)Windows系统

短文――《荔枝图序》《山市》

有关后门的知识详解 武林安全网

内核完全注释1makefileUnix系统
《内核完全注释1makefileUnix系统.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

【内核完全注释1makefileUnix系统(精选5篇)】相关文章:

会计电算系统数据接口设计思想与方法论文2022-08-05

生物培养能力要落在实处2022-12-16

操作系统实习报告2022-09-25

RFC1058路由信息协议(RoutingInformationProtocol)网络知识2023-12-18

《荔枝图序》教案2024-03-31

大学生论文2022-05-07

FreeBSD 5.3下中文显示Unix系统2023-02-19

坚固的近义词解析查询2022-10-16

太阳热水器设计分析的论文2023-11-29

JAVA WEB面试笔试题2022-05-07